Refactor thread cache management in allocators
Refactored thread-local stack allocator in AllocationManager to use ThreadLocalStackPool, removing global stack pointer arrays and locks. In FreeList, replaced fixed-size cache array and maxConcurrencyLevel with a dynamic linked-list system using SharedState and CacheReclaimer for thread cache lifecycle management. Block headers now store cache pointers instead of indices. Updated allocation/free logic and tests accordingly. Bumped assembly version to 3.1.3.
This commit is contained in:
@@ -57,7 +57,7 @@ public class TestAllocationManager
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void StackAllocationTest()
|
||||
public void StackAllocationTest()
|
||||
{
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
@@ -66,6 +66,8 @@ public class TestAllocationManager
|
||||
|
||||
Assert.IsTrue(ptr1.IsCreated);
|
||||
|
||||
Thread.Sleep(100); // Simulate some work
|
||||
|
||||
ptr1.Dispose();
|
||||
scope.Dispose();
|
||||
});
|
||||
@@ -73,6 +75,8 @@ public class TestAllocationManager
|
||||
thread.Start();
|
||||
|
||||
var scope = AllocationManager.CreateStackScope();
|
||||
Assert.AreEqual(0u, scope.OriginalOffset);
|
||||
|
||||
var ptr2 = new MemoryBlock(1024, 8, scope.AllocationHandle);
|
||||
|
||||
Assert.IsTrue(ptr2.IsCreated);
|
||||
|
||||
@@ -40,7 +40,7 @@ public unsafe class TestFreeList
|
||||
{
|
||||
const int threadCount = 8;
|
||||
const int iterations = 1000;
|
||||
using var freeList = new FreeList(8, 64 * 1024, threadCount);
|
||||
using var freeList = new FreeList(8, 64 * 1024);
|
||||
|
||||
var threads = new Thread[threadCount];
|
||||
for (var i = 0; i < threadCount; i++)
|
||||
@@ -68,7 +68,7 @@ public unsafe class TestFreeList
|
||||
const int producerCount = 4;
|
||||
const int consumerCount = 4;
|
||||
const int iterations = 5000;
|
||||
using var freeList = new FreeList(8, 64 * 1024, producerCount + consumerCount);
|
||||
using var freeList = new FreeList(8, 64 * 1024);
|
||||
|
||||
var queue = new System.Collections.Concurrent.ConcurrentQueue<IntPtr>();
|
||||
var producers = new Thread[producerCount];
|
||||
@@ -124,7 +124,7 @@ public unsafe class TestFreeList
|
||||
{
|
||||
// Set maxConcurrencyLevel to 1, but use more threads
|
||||
const int threadCount = 5;
|
||||
using var freeList = new FreeList(8, 1024, 1);
|
||||
using var freeList = new FreeList(8, 1024);
|
||||
|
||||
var threads = new Thread[threadCount];
|
||||
for (var i = 0; i < threadCount; i++)
|
||||
|
||||
Reference in New Issue
Block a user