public IDisposable AcquireLock(LockType lockType, string instanceId) { while (true) { EnsureObjectNotDisposed(); if (_lockRepository.TryAcquireLock(lockType, instanceId)) { var lockInstance = new LockInstance(this, lockType, instanceId); AddLock(lockInstance); return(lockInstance); } Thread.Sleep(SleepThreshold); } }
private async Task ReleaseLock(LockInstance lockInstance) { await _pendingLocksSemaphore.WaitAsync(); try { _lockRepository.ReleaseLock(lockInstance.LockType, lockInstance.InstanceId).ConfigureAwait(false).GetAwaiter().GetResult(); LockReleased(lockInstance); } finally { _pendingLocksSemaphore.Release(); } }
//**************************************** internal Instance(LockInstance instance) { _Instance = instance; _Token = instance.Version; }