A CSpace
is protected by a mutex.
The following functions on a CSpace
allow for locking and unlocking it:
$adt+ CSpace
{
void Lock(ECSpaceLockMode mode);
void Unlock();
LockInfo BeginUnlock();
void EndUnlock(LockInfo info);
};
void Lock(ECSpaceLockMode mode)
Blocks the calling thread until it successfully gains a lock of the given ECSpaceLockMode on the CSpace. Locking multiple CSpaces must be done in a specific order.
void Unlock()
Release the lock on the CSpace. Must be called by the thread that locked the CSpace by calling Lock()
LockInfo BeginUnlock()
Used in the implementation of CSpaceRelinquishLock to relinquish the lock. The returned LockInfo allows for subsequently calling EndUnlock() to reinstate the lock.
void EndUnlock(LockInfo info)
Reinstates the lock that was previously relinquished by calling BeginUnlock.
The RAII classes CSpaceLock and CSpaceTxn allow for locking a CSpace in a given scope.
The RAII class CSpaceRelinquishLock allows for relinquishing a lock in a given scope.
Uncaught exceptions which are thrown while locking a CSpace mutex are regarded as a programming error, and the safest thing to do is to immediately terminate the process - rather than risk persisting objects in an invalid state to a database perhaps causing permanent data coruption or loss.