back to matrix

This commit is contained in:
Youmu Liu
2026-03-23 20:11:08 +08:00
parent 0ac7b2b71f
commit eee88e1098
10 changed files with 100 additions and 179 deletions
@@ -41,23 +41,23 @@ namespace StgSharp.Mathematics.Numeric
private static AwaitingQueue _awaitingLeaderHandle;
private static volatile int _createGeneration = 0;
private static volatile int _createGeneration;
private static int _sortState;
public static MatrixParallelThread[] LeadParallel(
int recommendCount
long recommendCount
)
{
int min = int.Min(recommendCount, _threads.Capacity);
int recommend = (recommendCount > int.MaxValue) ? int.MaxValue : ((int)recommendCount);
int min = (int)long.Min(recommend, _threads.Capacity);
min /= 2;
MatrixParallelThread[] ret;
if (_threads.Count < min)
{
WaitHandle handle = new WaitHandle
(
WaitHandle handle = new(
_createGeneration,
min,
recommendCount
recommend
);
do
{
@@ -65,7 +65,7 @@ namespace StgSharp.Mathematics.Numeric
{
_awaitingLeaderHandle.Enqueue(handle);
_ = Interlocked.Exchange(ref _sortState, 0);
Interlocked.Increment(ref _createGeneration);
_ = Interlocked.Increment(ref _createGeneration);
break;
}
} while (true);
@@ -100,7 +100,7 @@ namespace StgSharp.Mathematics.Numeric
{
if (Interlocked.Exchange(ref _sortState, 1) == 0)
{
ret = _threads.PopRange(recommendCount);
ret = _threads.PopRange(recommend);
_createGeneration++;
_ = Interlocked.Exchange(ref _sortState, 0);
return ret;
@@ -120,7 +120,7 @@ namespace StgSharp.Mathematics.Numeric
if (Interlocked.Exchange(ref _sortState, 1) == 0)
{
_threads.PushRange(pool);
Interlocked.Exchange(ref _sortState, 0);
_ = Interlocked.Exchange(ref _sortState, 0);
break;
}
}