Exemple #1
0
 //- TODO : Since this is an explicit implementation, it the only thing that should
 //  end up calling it is a using() statement.  Still, we should weigh the convenience
 //  of this against the fact that it could create harder to find errors if someone
 //  used the lock in a way I didn't anticipate, and ends up calling this at the wrong time.
 void IDisposable.Dispose()
 {
     if (lockState.IsReadLocked())
     {
         Locksmith.ExitReadLock(ref lockState, readLockObject, this);
     }
     else if (lockState.IsWriteLocked())
     {
         Locksmith.ExitWriteLock(ref lockState, readLockObject, this);
     }
     else
     {
         throw new SynchronizationLockException(
                   $"A process used the Dispose() method of a {nameof(ReaderWriterLock)} to try to exit a lock, " +
                   $"but the lock was not in a locked state");
     }
 }
Exemple #2
0
            public ReaderWriterLock Upgrade()
            {
                Locksmith.Upgrade(ref lockState, this);

                return(this);
            }
Exemple #3
0
            public ReaderWriterLock Downgrade()
            {
                Locksmith.EnterReadLock(ref lockState, readLockObject);

                return(this);
            }
Exemple #4
0
            public ReaderWriterLock WriteLock()
            {
                Locksmith.EnterWriteLock(ref lockState, this);

                return(this);
            }