int stateCheck = isUpgradable ? RwWaitUpgrade + RwWait : RwWait;
long start = millisecondsTimeout == -1 ? 0 : sw.ElapsedMilliseconds;
+ int registration = isUpgradable ? RwWaitUpgrade : RwWait;
do {
int state = rwlock;
if (state <= stateCheck) {
try {}
finally {
- if (Interlocked.CompareExchange (ref rwlock, RwWrite, state) == state) {
+ var toWrite = state + RwWrite - (registered ? registration : 0);
+ if (Interlocked.CompareExchange (ref rwlock, toWrite, state) == state) {
writerDoneEvent.Reset ();
ctstate.LockState ^= LockState.Write;
++ctstate.WriterRecursiveCount;
return rwlock >= RwRead && CurrentThreadState.LockState.Has (LockState.Read);
}
}
-
+
public bool IsWriteLockHeld {
get {
return (rwlock & RwWrite) > 0 && CurrentThreadState.LockState.Has (LockState.Write);