RecyclableLongList.IndexOf stability & performance improvements.

This commit is contained in:
mlemanczyk committed 2023-06-04 17:21:44 +02:00
1 parent e3ca5b4f87
commit fb689e84d6
4 files changed
+298 -81

No files matched your search

@@ -0,0 +1,26 @@
namespace Recyclable.Collections.Parallel
{
public struct SpinLockSlimmer
{
private volatile int _locked;
public void Enter()
{
if (Interlocked.CompareExchange(ref _locked, 1, 0) == 0)
{
return;
}
SpinWait waiter = new();
while (Interlocked.CompareExchange(ref _locked, 1, 0) == 1)
{
waiter.SpinOnce();
}
}
public void Exit()
{
_locked = 0;
}
}
}