Isolate CPU divisor pools per thread
This commit is contained in:
1 parent
cd69c08fb4
commit
8e9390bc5e
7 files changed
+61
-34
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
internal static class ThreadLocalArrayPool<T>
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static ArrayPool<T>? s_threadPool;
|
||||
|
||||
public static ArrayPool<T> Shared
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ArrayPool<T>? pool = s_threadPool;
|
||||
if (pool is null)
|
||||
{
|
||||
pool = ArrayPool<T>.Create();
|
||||
s_threadPool = pool;
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user