Skip to content

Commit

Permalink
Enabled pooling by default. Optimizations for .NET 9.0+.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Jul 21, 2024
1 parent c522d87 commit 55a0544
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions AsyncKeyedLock/AsyncKeyedLocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,34 +1743,48 @@ public bool IsInUse(TKey key)
{
return false;
}

if (_dictionary.PoolingEnabled)
{
#if NET9_0_OR_GREATER
result.Lock.Enter();
result.Lock.Enter();
#else
Monitor.Enter(result);
Monitor.Enter(result);
#endif
if (result.IsNotInUse)
{
if (result.IsNotInUse)
{
#if NET9_0_OR_GREATER
result.Lock.Exit();
result.Lock.Exit();
#else
Monitor.Exit(result);
Monitor.Exit(result);
#endif
return false;
}
if (_dictionary.PoolingEnabled && !result.Key.Equals(key))
{
return false;
}
if (!result.Key.Equals(key))
{
#if NET9_0_OR_GREATER
result.Lock.Exit();
result.Lock.Exit();
#else
Monitor.Exit(result);
Monitor.Exit(result);
#endif
return false;
}
return false;
}
#if NET9_0_OR_GREATER
result.Lock.Exit();
result.Lock.Exit();
#else
Monitor.Exit(result);
Monitor.Exit(result);
#endif
}
else
{
Monitor.Enter(result);
if (result.IsNotInUse)
{
Monitor.Exit(result);
return false;
}
Monitor.Exit(result);
}
return true;
}

Expand Down

0 comments on commit 55a0544

Please sign in to comment.