Skip to content

Commit 7ae8994

Browse files
committed
Don't use Interlocked.Increment/Decrement when we have the lock
It makes it hard to figure out what needs to be accessed atomically and what doesn't. Since we have the _reentrances lock for both the increment and the decrement, there is no need for the explicit Interlocked call here.
1 parent e8150fa commit 7ae8994

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

AsyncLock/AsyncLock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private bool InnerTryEnter(bool synchronous = false)
273273
}
274274

275275
// We can go in
276-
Interlocked.Increment(ref _parent._reentrances);
276+
_parent._reentrances += 1;
277277
result = true;
278278
return result;
279279
}
@@ -302,7 +302,7 @@ public void Dispose()
302302
@this._parent._reentrancy.Wait();
303303
try
304304
{
305-
Interlocked.Decrement(ref @this._parent._reentrances);
305+
@this._parent._reentrances -= 1;
306306
@this._parent._owningId = oldId;
307307
@this._parent._owningThreadId = oldThreadId;
308308
if (@this._parent._reentrances == 0)

0 commit comments

Comments
 (0)