find a way to create Thread binded to LogicalCore properly

This commit is contained in:
Youmu Liu
2026-04-13 19:01:28 +08:00
parent 61a5b49c22
commit b07013a003
2 changed files with 20 additions and 1 deletions
@@ -59,6 +59,25 @@ namespace StgSharp.Common.HighPerformance.ProcessorAbstraction
return NumaAllocNative(size, numaId);
}
public static T[][] CreateForeachThread<T>(
Func<LogicalCore, T> factory
)
{
if (factory is null) {
return [];
}
T[][] arr = new T[_numaNodes.Length][];
foreach (NumaNode node in _numaNodes)
{
T[] values = new T[node.LogicalCoreCount];
ReadOnlySpan<LogicalCore> cores = node.LogicalCores;
for (int i = 0; i < cores.Length; i++) {
values[i] = factory(cores[i]);
}
}
return arr;
}
public static unsafe void Free(
void* address,
int numaId,