Cleanup of no longer needed classes. ParallelSynchronizationContext/-Pool renamed to IndexOfSynchronizationContext/-Pool.

This commit is contained in:
mlemanczyk committed 2023-05-21 16:10:21 +02:00
1 parent 9ece531129
commit 24c2491df0
9 files changed
+80 -255

No files matched your search

-30
View File
@@ -1,30 +0,0 @@
using Recyclable.Collections.Pools;
namespace Recyclable.Collections
{
public sealed class ItemRange
{
public int BlockIndex;
public long ItemsToSearchCount;
internal bool _returned;
public ItemRange()
{
}
public ItemRange(int blockIndex, long itemsToSearchCount)
{
BlockIndex = blockIndex;
ItemsToSearchCount = itemsToSearchCount;
}
public void Dispose()
{
if (!_returned)
{
_returned = true;
ItemRangePool.Shared.Return(this);
}
}
}
}
@@ -1,30 +0,0 @@
using System.Runtime.CompilerServices;
using Recyclable.Collections.Parallel;
namespace Recyclable.Collections
{
public static class ItemRangesIterator
{
[MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining)]
public static void Iterate<TList, T>(in ParallelSynchronizationContext context, in SearchConfiguration<TList, T> search, Func<ParallelSynchronizationContext, SearchConfiguration<TList, T>, ItemRange, bool> action)
{
ItemRange itemRange;
int blockIndex = search.StartingBlockIndex;
long itemsCount = search.ItemsCount;
while (itemsCount > search.BlockSize)
{
itemRange = new(blockIndex, search.BlockSize);
if (!action(context, search, itemRange))
{
break;
}
itemsCount -= search.BlockSize;
blockIndex++;
}
itemRange = new(blockIndex, itemsCount);
_ = action(context, search, itemRange);
}
}
}
@@ -1,6 +1,6 @@
namespace Recyclable.Collections.Parallel
{
public sealed class ParallelSynchronizationContext : IDisposable
public sealed class IndexOfSynchronizationContext : IDisposable
{
internal bool _isItemFound;
@@ -9,12 +9,12 @@ namespace Recyclable.Collections.Parallel
public Exception? Exception;
internal bool _returned;
public ParallelSynchronizationContext()
public IndexOfSynchronizationContext()
{
AllDoneSignal = new(0);
}
public ParallelSynchronizationContext(int participantCount)
public IndexOfSynchronizationContext(int participantCount)
{
AllDoneSignal = new(participantCount);
}
@@ -31,7 +31,7 @@ namespace Recyclable.Collections.Parallel
if (!_returned)
{
_returned = true;
ParallelSynchronizationContextPool.Shared.Return(this);
IndexOfSynchronizationContextPool.Shared.Return(this);
}
else
{
@@ -2,12 +2,12 @@ using Microsoft.Extensions.ObjectPool;
namespace Recyclable.Collections.Parallel
{
public static class ParallelSynchronizationContextPool
public static class IndexOfSynchronizationContextPool
{
private static readonly SpinLock _updateLock = new(false);
public static readonly ObjectPool<ParallelSynchronizationContext> Shared = new DefaultObjectPool<ParallelSynchronizationContext>(new DefaultPooledObjectPolicy<ParallelSynchronizationContext>());
public static readonly ObjectPool<IndexOfSynchronizationContext> Shared = new DefaultObjectPool<IndexOfSynchronizationContext>(new DefaultPooledObjectPolicy<IndexOfSynchronizationContext>());
public static ParallelSynchronizationContext GetWithOneParticipant()
public static IndexOfSynchronizationContext GetWithOneParticipant()
{
bool lockTaken = false;
_updateLock.Enter(ref lockTaken);
@@ -1,26 +0,0 @@
using Microsoft.Extensions.ObjectPool;
namespace Recyclable.Collections.Pools
{
public static class ItemRangePool
{
private static readonly SpinLock _updateLock = new(false);
public static readonly ObjectPool<ItemRange> Shared = new DefaultObjectPool<ItemRange>(new DefaultPooledObjectPolicy<ItemRange>());
public static ItemRange Create(int blockIndex, long itemsToSearchCount)
{
bool lockTaken = false;
_updateLock.Enter(ref lockTaken);
var itemRange = Shared.Get();
if (lockTaken)
{
_updateLock.Exit(false);
}
itemRange._returned = false;
itemRange.BlockIndex = blockIndex;
itemRange.ItemsToSearchCount = itemsToSearchCount;
return itemRange;
}
}
}
@@ -5,12 +5,12 @@ namespace Recyclable.Collections
{
public partial class RecyclableList<T>
{
public static class RecyclableListIndexOfHelpers
public static class IndexOfHelpers
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoOptimization)]
private static void ScheduleIndexOfTask(ParallelSynchronizationContext context, RecyclableList<T> list, int blockIndex, T itemToFind)
private static void ScheduleIndexOfTask(IndexOfSynchronizationContext context, RecyclableList<T> list, int blockIndex, T itemToFind)
{
_ = context.AllDoneSignal.AddParticipant();
// & WAS SLOWER
@@ -123,7 +123,7 @@ namespace Recyclable.Collections
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoOptimization)]
private static void ScheduleIndexOfTaskSingle(ParallelSynchronizationContext context, RecyclableList<T> list, int blockIndex, T itemToFind)
private static void ScheduleIndexOfTaskSingle(IndexOfSynchronizationContext context, RecyclableList<T> list, int blockIndex, T itemToFind)
{
_ = context.AllDoneSignal.AddParticipant();
// & WAS SLOWER
@@ -172,7 +172,7 @@ namespace Recyclable.Collections
//}
//using var context = new ParallelSynchronizationContext(1);
ParallelSynchronizationContext context = ParallelSynchronizationContextPool.GetWithOneParticipant();
IndexOfSynchronizationContext context = IndexOfSynchronizationContextPool.GetWithOneParticipant();
// (long)(_longCount * 0.329) => most efficient step, based on benchmarks
//Iterate(this, context, item);
+4 -4
View File
@@ -857,7 +857,7 @@ namespace Recyclable.Collections
}
else if (_longCount < RecyclableDefaults.MinItemsCountForParallelization)
{
return (int)RecyclableListIndexOfHelpers.IndexOfSequential(this, item);
return (int)IndexOfHelpers.IndexOfSequential(this, item);
}
else
{
@@ -866,7 +866,7 @@ namespace Recyclable.Collections
if (_longCount > _blockSize)
{
itemIndex = Array.IndexOf(_memoryBlocks[1], item, 0, (int)Math.Min(_blockSize, _longCount - _blockSize));
return itemIndex >= 0 ? _blockSize + itemIndex : (int)RecyclableListIndexOfHelpers.IndexOfParallel(this, item);
return itemIndex >= 0 ? _blockSize + itemIndex : (int)IndexOfHelpers.IndexOfParallel(this, item);
}
else
{
@@ -896,7 +896,7 @@ namespace Recyclable.Collections
}
else if (_longCount < RecyclableDefaults.MinItemsCountForParallelization)
{
return RecyclableListIndexOfHelpers.IndexOfSequential(this, item);
return IndexOfHelpers.IndexOfSequential(this, item);
}
else
{
@@ -905,7 +905,7 @@ namespace Recyclable.Collections
if (_longCount > _blockSize)
{
itemIndex = Array.IndexOf(_memoryBlocks[1], item, 0, (int)Math.Min(_blockSize, _longCount - _blockSize));
return itemIndex >= 0 ? _blockSize + itemIndex : RecyclableListIndexOfHelpers.IndexOfParallel(this, item);
return itemIndex >= 0 ? _blockSize + itemIndex : IndexOfHelpers.IndexOfParallel(this, item);
}
else
{