Skip to content

Commit 7b53e0c

Browse files
author
Alex Peck
committed
net9
1 parent 836281f commit 7b53e0c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

BitFaster.Caching/BitFaster.Caching.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
5-
<LangVersion>10.0</LangVersion>
4+
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net9.0</TargetFrameworks>
5+
<LangVersion>13.0</LangVersion>
66
<Authors>Alex Peck</Authors>
77
<Company />
88
<Product>BitFaster.Caching</Product>

BitFaster.Caching/Lfu/ConcurrentLfuCore.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ internal struct ConcurrentLfuCore<K, V, N, P> : IBoundedPolicy
6464
private readonly LfuCapacityPartition capacity;
6565

6666
internal readonly DrainStatus drainStatus = new();
67-
private readonly object maintenanceLock = new();
6867

68+
#if NET9_0_OR_GREATER
69+
private readonly Lock maintenanceLock = new();
70+
#else
71+
private readonly object maintenanceLock = new();
72+
#endif
6973
private readonly IScheduler scheduler;
7074
private readonly Action drainBuffers;
7175

@@ -484,7 +488,12 @@ private void TryScheduleDrain()
484488
bool lockTaken = false;
485489
try
486490
{
491+
#if NET9_0_OR_GREATER
492+
lockTaken = maintenanceLock.TryEnter();
493+
#else
487494
Monitor.TryEnter(maintenanceLock, ref lockTaken);
495+
#endif
496+
488497

489498
if (lockTaken)
490499
{
@@ -503,7 +512,11 @@ private void TryScheduleDrain()
503512
{
504513
if (lockTaken)
505514
{
506-
Monitor.Exit(maintenanceLock);
515+
#if NET9_0_OR_GREATER
516+
maintenanceLock.Exit();
517+
#else
518+
Monitor.Exit(maintenanceLock);
519+
#endif
507520
}
508521
}
509522
}

0 commit comments

Comments
 (0)