Small cleanup
This commit is contained in:
1 parent
bb878caa39
commit
53d759586e
6 files changed
+66
-66
No files matched your search
@@ -2,7 +2,7 @@ using Recyclable.Collections.Pools;
|
||||
|
||||
namespace Recyclable.Collections
|
||||
{
|
||||
public sealed class ItemRange
|
||||
public sealed class ItemRange
|
||||
{
|
||||
public int BlockIndex;
|
||||
public int StartingItemIndex;
|
||||
|
||||
@@ -2,49 +2,49 @@ using Microsoft.Extensions.ObjectPool;
|
||||
|
||||
namespace Recyclable.Collections.Parallel
|
||||
{
|
||||
public static class ParallelSynchronizationContextPool
|
||||
{
|
||||
private static readonly SpinLock _updateLock = new(false);
|
||||
public static readonly ObjectPool<ParallelSynchronizationContext> Shared = new DefaultObjectPool<ParallelSynchronizationContext>(new DefaultPooledObjectPolicy<ParallelSynchronizationContext>());
|
||||
public static class ParallelSynchronizationContextPool
|
||||
{
|
||||
private static readonly SpinLock _updateLock = new(false);
|
||||
public static readonly ObjectPool<ParallelSynchronizationContext> Shared = new DefaultObjectPool<ParallelSynchronizationContext>(new DefaultPooledObjectPolicy<ParallelSynchronizationContext>());
|
||||
|
||||
public static ParallelSynchronizationContext GetWithOneParticipant()
|
||||
{
|
||||
bool lockTaken = false;
|
||||
_updateLock.Enter(ref lockTaken);
|
||||
var context = Shared.Get();
|
||||
if (lockTaken)
|
||||
{
|
||||
_updateLock.Exit(false);
|
||||
}
|
||||
public static ParallelSynchronizationContext GetWithOneParticipant()
|
||||
{
|
||||
bool lockTaken = false;
|
||||
_updateLock.Enter(ref lockTaken);
|
||||
var context = Shared.Get();
|
||||
if (lockTaken)
|
||||
{
|
||||
_updateLock.Exit(false);
|
||||
}
|
||||
|
||||
if (context.ItemFoundSignal._isSet)
|
||||
{
|
||||
context.ItemFoundSignal.Reset();
|
||||
}
|
||||
if (context.ItemFoundSignal._isSet)
|
||||
{
|
||||
context.ItemFoundSignal.Reset();
|
||||
}
|
||||
|
||||
switch (context.AllDoneSignal.ParticipantsRemaining)
|
||||
{
|
||||
case > 1:
|
||||
context.AllDoneSignal.RemoveParticipants(context.AllDoneSignal.ParticipantsRemaining - 1);
|
||||
break;
|
||||
switch (context.AllDoneSignal.ParticipantsRemaining)
|
||||
{
|
||||
case > 1:
|
||||
context.AllDoneSignal.RemoveParticipants(context.AllDoneSignal.ParticipantsRemaining - 1);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
context.AllDoneSignal.AddParticipant();
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
_ = context.AllDoneSignal.AddParticipant();
|
||||
break;
|
||||
}
|
||||
|
||||
if (context.Exception != null)
|
||||
{
|
||||
context.Exception = null;
|
||||
}
|
||||
if (context.Exception != null)
|
||||
{
|
||||
context.Exception = null;
|
||||
}
|
||||
|
||||
if (context.FoundItemIndex >= 0)
|
||||
{
|
||||
context.FoundItemIndex = -1L;
|
||||
}
|
||||
if (context.FoundItemIndex >= 0)
|
||||
{
|
||||
context.FoundItemIndex = -1L;
|
||||
}
|
||||
|
||||
context._returned = false;
|
||||
return context;
|
||||
}
|
||||
}
|
||||
context._returned = false;
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user