/// <summary> /// Initializes a new instance of the <see cref="SlimReaderWriterLock"/> class. /// </summary> public SlimReaderWriterLock() { #if MONO throw new NotSupportedException(ExceptionText); #else _rwLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); ReadLock = new CommonReadLock(this); WriteLock = new CommonWriteLock(this); _rDisposable = new TrackedDisposable(ReleaseReaderLock); _wDisposable = new TrackedDisposable(ReleaseWriterLock); #endif }
public IDisposable Acquire(bool releaseLock, long?msec = null) { var timeLockRequested = PerformanceObserver.MicroTime; var disposableLock = _subLock.Acquire(releaseLock, msec: msec); var timeLockAcquired = PerformanceObserver.MicroTime; var disposableTrack = new TrackedDisposable( delegate { disposableLock.Dispose(); disposableLock = null; FinishTrackingPerformance(timeLockRequested, timeLockAcquired); }); return(disposableTrack); }
/// <summary> /// Initializes a new instance of the <see cref="SlimReaderWriterLock"/> class. /// </summary> public SlimReaderWriterLock(int lockTimeout) { _id = Guid.NewGuid(); _lockTimeout = lockTimeout; #if MONO throw new NotSupportedException(ExceptionText); #else _rwLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); ReadLock = new CommonReadLock(this, _lockTimeout); WriteLock = new CommonWriteLock(this, _lockTimeout); _rDisposable = new TrackedDisposable(ReleaseReaderLock); _wDisposable = new TrackedDisposable(ReleaseWriterLock); #endif }
/// <summary> /// Initializes a new instance of the <see cref="WriterLock"/> class. /// </summary> /// <param name="lockObj">The lock obj.</param> internal WriterLock(BlitReaderWriterLock lockObj) { LockObj = lockObj; Disposable = new TrackedDisposable(LockObj.ReleaseWriterLock); }