AcquireLock

(System Library)

Description: Subroutine to acquire an exclusive lock on reading / writing working copy files across all applications.
Warning: This function should be used only by advanced programmers.
Returns: Semaphore via the third parameter
Usage: Script Only.
Function Groups: Configuration Management
Related to: ReleaseLock |
Format: System.Acquirelock(WritePermission, Owner, SemaphorePtr[, WritingUserID])
Parameters:  
WritePermission
Required. Any BOOLEAN expression. Set TRUE if the owner intends to perform writes or FALSE for read-only access.
Owner
Required. The instance of the lock owner.
SemaphorePtr
Required. A pointer that will be set TRUE when the semaphore is granted.
WritingUserID
Optional. User ID for the user acquiring the lock. Should be used if the user is going to make working copy changes and not commit them within the lock, so that the correct User ID is assigned to the changes when they are committed.
Comments:

This function should be called before performing any modification of any application’s working copy. The output of this function is a semaphore that guarantees exclusive access to the working copy until it is released.

Note that the caller must wait for the semaphore to become TRUE (1), which indicates that the lock is held.

A lock gathered by AcquireLock should be released by calling ReleaseLock. It is automatically released when the variable used to collect the semaphore is released during calling object destruction. This module launches a destructor module so that if the caller to this module stops, the destructor will continue to run until ReleaseLock is called or one of the parameters becomes invalid.

Because this lock prevents any other access to the working copy, you should minimize the length of time it will be held.

Examples:

GetLayerLock [
  If 1 WaitForLock;
  [
    System.AcquireLock(1 {write}, Self, &LayerLock);
  ]
]
 
WaitForLock [
  If LayerLock;
  [
     { process files }
  ]
]