File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -82,23 +82,23 @@ public async Task<Releaser> WriteLockAsync()
8282
8383 public Releaser ReadLock ( )
8484 {
85- if ( CanEnterReadLock ( ) )
85+ if ( CanEnterReadLock ( out var waitingReadLockSemaphore ) )
8686 {
8787 return _readerReleaser ;
8888 }
8989
90- _waitingReadLockSemaphore . Wait ( ) ;
90+ waitingReadLockSemaphore . Wait ( ) ;
9191
9292 return _readerReleaser ;
9393 }
9494
9595 public Task < Releaser > ReadLockAsync ( )
9696 {
97- return CanEnterReadLock ( ) ? _readerReleaserTask : ReadLockInternalAsync ( ) ;
97+ return CanEnterReadLock ( out var waitingReadLockSemaphore ) ? _readerReleaserTask : ReadLockInternalAsync ( ) ;
9898
9999 async Task < Releaser > ReadLockInternalAsync ( )
100100 {
101- await _waitingReadLockSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
101+ await waitingReadLockSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
102102
103103 return _readerReleaser ;
104104 }
@@ -165,14 +165,15 @@ private void ExitWriteLock()
165165 }
166166 }
167167
168- private bool CanEnterReadLock ( )
168+ private bool CanEnterReadLock ( out SemaphoreSlim waitingReadLockSemaphore )
169169 {
170170 lock ( _writeLockSemaphore )
171171 {
172172 AssertNotDisposed ( ) ;
173173 if ( _writersWaiting == 0 && _writeLockSemaphore . CurrentCount > 0 )
174174 {
175175 _currentReaders ++ ;
176+ waitingReadLockSemaphore = null ;
176177
177178 return true ;
178179 }
@@ -183,6 +184,7 @@ private bool CanEnterReadLock()
183184 }
184185
185186 _readersWaiting ++ ;
187+ waitingReadLockSemaphore = _waitingReadLockSemaphore ;
186188
187189 return false ;
188190 }
You can’t perform that action at this time.
0 commit comments