/// <summary> /// Acquires the writer lock. /// </summary> /// <param name="timeoutMilliseconds">The timeout milliseconds.</param> /// <param name="releaser">The releaser.</param> /// <returns>Success.</returns> private bool AcquireWriterLock(int timeoutMilliseconds, out IDisposable releaser) { if (m_IsDisposed == true) { throw new ObjectDisposedException(nameof(ISyncLocker)); } releaser = SyncLockReleaser.Empty; bool result; if (Locker.IsReadLockHeld) { result = Locker.TryEnterReadLock(timeoutMilliseconds); if (result) { releaser = new SyncLockReleaser(this, LockHolderType.Read); } return(result); } result = Locker.TryEnterWriteLock(timeoutMilliseconds); if (result) { releaser = new SyncLockReleaser(this, LockHolderType.Write); } return(result); }
/// <summary> /// Acquires the reader lock. /// </summary> /// <param name="timeoutMilliseconds">The timeout milliseconds.</param> /// <param name="releaser">The releaser.</param> /// <returns>Success</returns> private bool AcquireReaderLock(int timeoutMilliseconds, out IDisposable releaser) { releaser = SyncLockReleaser.Empty; var result = Locker?.TryEnterReadLock(timeoutMilliseconds) ?? false; if (result) { releaser = new SyncLockReleaser(this, LockHolderType.Read); } return(result); }
/// <summary> /// Acquires the reader lock. /// </summary> /// <param name="timeoutMilliseconds">The timeout milliseconds.</param> /// <param name="releaser">The releaser.</param> /// <returns>Success</returns> private bool AcquireReaderLock(int timeoutMilliseconds, out IDisposable releaser) { releaser = SyncLockReleaser.Empty; Locker?.AcquireReaderLock(timeoutMilliseconds); if (Locker?.IsReaderLockHeld ?? false) { releaser = new SyncLockReleaser(this, LockHolderType.Read); return(true); } return(false); }
/// <summary> /// Acquires the reader lock. /// </summary> /// <param name="timeoutMilliseconds">The timeout milliseconds.</param> /// <param name="releaser">The releaser.</param> /// <returns>Success.</returns> private bool AcquireReaderLock(int timeoutMilliseconds, out IDisposable releaser) { if (m_IsDisposed == true) { throw new ObjectDisposedException(nameof(ISyncLocker)); } releaser = SyncLockReleaser.Empty; Locker.AcquireReaderLock(timeoutMilliseconds); if (!Locker.IsReaderLockHeld) { return(false); } releaser = new SyncLockReleaser(this, LockHolderType.Read); return(true); }
/// <summary> /// Acquires the reader lock. /// </summary> /// <param name="timeoutMilliseconds">The timeout milliseconds.</param> /// <param name="releaser">The releaser.</param> /// <returns>Success</returns> private bool AcquireReaderLock(int timeoutMilliseconds, out IDisposable releaser) { if (m_IsDisposed == true) { throw new ObjectDisposedException(nameof(ISyncLocker)); } releaser = SyncLockReleaser.Empty; var result = Locker?.TryEnterReadLock(timeoutMilliseconds) ?? false; if (result) { releaser = new SyncLockReleaser(this, LockHolderType.Read); } return(result); }