public void AcquireGlobalLock() { lock (_sync_mutex) { //wait untill global lock is released. if (_globalLockingContext != null && _globalLockingContext.IsCurrentContext) { _globalLockingContext.IncrementRefCount(); return; } while (_globalLock || _waiting4globalLock) { Monitor.Wait(_sync_mutex); } if (_lockTable.Count == 0) { //global lock is acquired. _globalLock = true; } else { _waiting4globalLock = true; _globalLockInfo = new LockInfo(); } } if (_globalLockInfo != null && !_globalLock) { _globalLockInfo.AddWaitingThread(); } _globalLockingContext = new LockingContext(); _globalLockingContext.IncrementRefCount(); }
public void ReleaseGlobalLock() { lock (_sync_mutex) { if (_globalLockingContext.IsCurrentContext && _globalLockingContext.DecrementRefCount()) { _globalLock = false; _globalLockInfo = null; _globalLockingContext = null; Monitor.PulseAll(_sync_mutex); } } }