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()
82
82
83
83
public Releaser ReadLock ( )
84
84
{
85
- if ( CanEnterReadLock ( ) )
85
+ if ( CanEnterReadLock ( out var waitingReadLockSemaphore ) )
86
86
{
87
87
return _readerReleaser ;
88
88
}
89
89
90
- _waitingReadLockSemaphore . Wait ( ) ;
90
+ waitingReadLockSemaphore . Wait ( ) ;
91
91
92
92
return _readerReleaser ;
93
93
}
94
94
95
95
public Task < Releaser > ReadLockAsync ( )
96
96
{
97
- return CanEnterReadLock ( ) ? _readerReleaserTask : ReadLockInternalAsync ( ) ;
97
+ return CanEnterReadLock ( out var waitingReadLockSemaphore ) ? _readerReleaserTask : ReadLockInternalAsync ( ) ;
98
98
99
99
async Task < Releaser > ReadLockInternalAsync ( )
100
100
{
101
- await _waitingReadLockSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
101
+ await waitingReadLockSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
102
102
103
103
return _readerReleaser ;
104
104
}
@@ -165,14 +165,15 @@ private void ExitWriteLock()
165
165
}
166
166
}
167
167
168
- private bool CanEnterReadLock ( )
168
+ private bool CanEnterReadLock ( out SemaphoreSlim waitingReadLockSemaphore )
169
169
{
170
170
lock ( _writeLockSemaphore )
171
171
{
172
172
AssertNotDisposed ( ) ;
173
173
if ( _writersWaiting == 0 && _writeLockSemaphore . CurrentCount > 0 )
174
174
{
175
175
_currentReaders ++ ;
176
+ waitingReadLockSemaphore = null ;
176
177
177
178
return true ;
178
179
}
@@ -183,6 +184,7 @@ private bool CanEnterReadLock()
183
184
}
184
185
185
186
_readersWaiting ++ ;
187
+ waitingReadLockSemaphore = _waitingReadLockSemaphore ;
186
188
187
189
return false ;
188
190
}
You can’t perform that action at this time.
0 commit comments