Daily update on 20251110-002339 by Nitload Youmu. Additional Message : Dynamic wrapping is ok, going on test.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ConcurrentCapacityFixedStack"
|
// file="ConcurrentCapacityFixedStack"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -37,33 +37,22 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
public static partial class MatrixParallel
|
public static partial class MatrixParallel
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Because caller of this class has its own sync object
|
||||||
|
* this queue will use no sync object internally.
|
||||||
|
*/
|
||||||
|
|
||||||
private class AwaitingQueue
|
private class AwaitingQueue
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ConcurrentQueue<WaitHandle> _fallback = [];
|
|
||||||
private Element _quickElements = new();
|
private Element _quickElements = new();
|
||||||
private volatile int _count;
|
private volatile int _count;
|
||||||
private volatile int _lastGeneration;
|
private volatile int _lastGeneration;
|
||||||
private readonly
|
private readonly Queue<WaitHandle> _fallback = [];
|
||||||
#if NET9_0_OR_GREATER
|
|
||||||
Lock
|
|
||||||
#else
|
|
||||||
object
|
|
||||||
#endif
|
|
||||||
sync = new();
|
|
||||||
|
|
||||||
public AwaitingQueue() { }
|
public AwaitingQueue() { }
|
||||||
|
|
||||||
public void Enqueue(WaitHandle handle)
|
public void Enqueue(WaitHandle handle)
|
||||||
{
|
|
||||||
if (_count > 7)
|
|
||||||
{
|
|
||||||
_fallback.Enqueue(handle);
|
|
||||||
Interlocked.Increment(ref _count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lock (sync)
|
|
||||||
{
|
{
|
||||||
if (_count > 7)
|
if (_count > 7)
|
||||||
{
|
{
|
||||||
@@ -74,7 +63,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
_quickElements[_count] = handle;
|
_quickElements[_count] = handle;
|
||||||
Interlocked.Increment(ref _count);
|
Interlocked.Increment(ref _count);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryDequeue(int generation, out WaitHandle handle)
|
public bool TryDequeue(int generation, out WaitHandle handle)
|
||||||
{
|
{
|
||||||
@@ -84,8 +72,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
handle = null!;
|
handle = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lock (sync)
|
|
||||||
{
|
|
||||||
if (_lastGeneration == generation)
|
if (_lastGeneration == generation)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
@@ -103,7 +89,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryPeek(int generation, out WaitHandle handle)
|
public bool TryPeek(int generation, out WaitHandle handle)
|
||||||
{
|
{
|
||||||
@@ -113,8 +98,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
handle = null!;
|
handle = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lock (sync)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
_quickElements[i].UpdatePriority(generation);
|
_quickElements[i].UpdatePriority(generation);
|
||||||
}
|
}
|
||||||
@@ -127,7 +110,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryPopIfRefEqual(int generation, ref WaitHandle handle)
|
public bool TryPopIfRefEqual(int generation, ref WaitHandle handle)
|
||||||
{
|
{
|
||||||
@@ -136,12 +118,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
handle = null!;
|
handle = null!;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lock (sync)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _count; i++) {
|
for (int i = 0; i < _count; i++) {
|
||||||
_quickElements[i].UpdatePriority(generation);
|
_quickElements[i].UpdatePriority(generation);
|
||||||
}
|
}
|
||||||
Element.Sort(_quickElements);
|
Element.Sort(ref _quickElements);
|
||||||
_lastGeneration = generation;
|
_lastGeneration = generation;
|
||||||
handle = _quickElements[0];
|
handle = _quickElements[0];
|
||||||
_count--;
|
_count--;
|
||||||
@@ -154,7 +134,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,11 +143,26 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
private WaitHandle value;
|
private WaitHandle value;
|
||||||
|
|
||||||
public static void Sort(Element e)
|
public static void Sort(ref Element e)
|
||||||
{
|
{
|
||||||
/*
|
int maxIdx = 0;
|
||||||
* yet to do
|
WaitHandle first = e[0];
|
||||||
*/
|
int maxPr = first?.Priority ?? int.MaxValue;
|
||||||
|
|
||||||
|
for (int i = 1; i < 8; i++)
|
||||||
|
{
|
||||||
|
WaitHandle cur = e[i];
|
||||||
|
int p = cur?.Priority ?? int.MinValue;
|
||||||
|
if (p > maxPr)
|
||||||
|
{
|
||||||
|
maxPr = p;
|
||||||
|
maxIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxIdx != 0) {
|
||||||
|
(e[0], e[maxIdx]) = (e[maxIdx], e[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel"
|
// file="MatrixParallel"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -75,7 +75,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
_threads.Push(new());
|
_threads.Push(new());
|
||||||
}
|
}
|
||||||
_awaitingLeaderHandle = new ConcurrentQueue<WaitHandle>();
|
_awaitingLeaderHandle = new AwaitingQueue();
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user