Skip to content

Commit 4c886f8

Browse files
committed
Remove dead code
1 parent df5cae6 commit 4c886f8

File tree

1 file changed

+0
-66
lines changed

1 file changed

+0
-66
lines changed

AsyncLock/AsyncLock.cs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -503,71 +503,5 @@ public bool TryLock(Action callback, TimeSpan timeout)
503503
}
504504
return true;
505505
}
506-
507-
#if TRY_LOCK_OUT_BOOL
508-
private static readonly NullDisposable NullDisposable = new();
509-
510-
public IDisposable TryLock(TimeSpan timeout, out bool locked)
511-
{
512-
var @lock = new InnerLock(this, _asyncId.Value, ThreadId);
513-
// Increment the async stack counter to prevent a child task from getting
514-
// the lock at the same time as a child thread.
515-
_asyncId.Value = Interlocked.Increment(ref AsyncLock.AsyncStackCounter);
516-
var result = @lock.TryObtainLock(timeout);
517-
locked = result is not null;
518-
return result ?? NullDisposable;
519-
}
520-
521-
// Make sure InnerLock.LockAsync() does not use await, because an async function triggers a snapshot of
522-
// the AsyncLocal value.
523-
public Task<IDisposable> TryLockAsync(CancellationToken ct, out bool locked)
524-
{
525-
var @lock = new InnerLock(this, _asyncId.Value, ThreadId);
526-
_asyncId.Value = Interlocked.Increment(ref AsyncLock.AsyncStackCounter);
527-
528-
locked = false;
529-
530-
unsafe
531-
{
532-
// This is safe because we are not actually in an async method
533-
fixed (bool *addr = &locked)
534-
{
535-
var addrLong = (ulong)addr;
536-
return @lock.TryObtainLockAsync(ct).ContinueWith((state) =>
537-
{
538-
var result = state.Result;
539-
*(bool*)addrLong = result is not null;
540-
return result ?? NullDisposable;
541-
}, TaskContinuationOptions.OnlyOnRanToCompletion);
542-
}
543-
}
544-
}
545-
546-
// Make sure InnerLock.LockAsync() does not use await, because an async function triggers a snapshot of
547-
// the AsyncLocal value.
548-
public Task<IDisposable> TryLockAsync(TimeSpan timeout, out bool locked)
549-
{
550-
var @lock = new InnerLock(this, _asyncId.Value, ThreadId);
551-
_asyncId.Value = Interlocked.Increment(ref AsyncLock.AsyncStackCounter);
552-
553-
locked = false;
554-
555-
unsafe
556-
{
557-
// This is safe because we are not actually in an async method
558-
fixed (bool* addr = &locked)
559-
{
560-
var addrLong = (ulong)addr;
561-
return @lock.TryObtainLockAsync(timeout).ContinueWith((state) =>
562-
{
563-
var result = state.Result;
564-
*(bool*)addrLong = result is not null;
565-
return result ?? NullDisposable;
566-
}, TaskContinuationOptions.OnlyOnRanToCompletion);
567-
}
568-
}
569-
}
570-
571-
#endif
572506
}
573507
}

0 commit comments

Comments
 (0)