Skip to content

Commit a1484c4

Browse files
author
Alex Peck
committed
simpler lock entry
1 parent 291a9f4 commit a1484c4

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

BitFaster.Caching/Lfu/ConcurrentLfuCore.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,15 @@ private void TryScheduleDrain()
485485
return;
486486
}
487487

488-
bool lockTaken = false;
489-
try
490-
{
491488
#if NET9_0_OR_GREATER
492-
lockTaken = maintenanceLock.TryEnter();
489+
if (maintenanceLock.TryEnter())
493490
#else
494-
Monitor.TryEnter(maintenanceLock, ref lockTaken);
491+
bool lockTaken = false;
492+
Monitor.TryEnter(maintenanceLock, ref lockTaken);
493+
if (lockTaken)
495494
#endif
496-
497-
498-
if (lockTaken)
495+
{
496+
try
499497
{
500498
int status = this.drainStatus.NonVolatileRead();
501499

@@ -507,16 +505,16 @@ private void TryScheduleDrain()
507505
this.drainStatus.VolatileWrite(DrainStatus.ProcessingToIdle);
508506
scheduler.Run(this.drainBuffers);
509507
}
510-
}
511-
finally
512-
{
513-
if (lockTaken)
514-
{
508+
finally
509+
{
515510
#if NET9_0_OR_GREATER
516-
maintenanceLock.Exit();
511+
maintenanceLock.Exit();
517512
#else
518-
Monitor.Exit(maintenanceLock);
519-
#endif
513+
if (lockTaken)
514+
{
515+
Monitor.Exit(maintenanceLock);
516+
}
517+
#endif
520518
}
521519
}
522520
}

0 commit comments

Comments
 (0)