daly update on 20230502 by nitload youmu

This commit is contained in:
YoumuLiu
2024-05-03 00:49:56 +08:00
parent 8149dfacb0
commit 66efce19fc
28 changed files with 236 additions and 222 deletions
+37 -29
View File
@@ -81,18 +81,29 @@ namespace StgSharp.Logic
public void Init(int threadCount)
{
foreach (var item in allNode)
if (threadCount!=0)
{
if (item.Value.IsNative)
foreach (var item in allNode)
{
nativeNodeList.Add(item.Value);
if (item.Value.IsNative)
{
nativeNodeList.Add(item.Value);
}
else
{
nodeList.Add(item.Value);
}
}
else
nativeNodeList.Sort();
PrepareTasks(threadCount);
}
else
{
foreach (var item in allNode)
{
nodeList.Add(item.Value);
}
}
nativeNodeList.Sort();
nodeList.Sort();
if (threadCount > nodeList.Count)
{
@@ -100,29 +111,31 @@ namespace StgSharp.Logic
"Thread setting error: amount of threads of this blueprint is larger than amount of nodes.", LogType.Warning);
threadCount = nodeList.Count;
}
for (int i = 0; i < threadCount; i++)
}
public void PrepareTasks(int count)
{
for (int i = 0; i < count; i++)
{
allThread.Add(new Task(
() =>
{
do
{
try
{
while (true)
{
RequestNextNode().Run();
}
}
catch (NodeClearException) { }
} while (!terminate());
}
));
allThread.Add(new Task(IndividualTask));
}
}
private void IndividualTask()
{
do
{
try
{
while (true)
{
RequestNextNode().Run();
}
}
catch (NodeClearException) { }
} while (!terminate());
}
/// <summary>
/// Run all nodes repeatedly until it is instructed to terminate.
/// </summary>
@@ -160,11 +173,6 @@ namespace StgSharp.Logic
private void SingleThreadRun(Func<bool> terminateInstructor)
{
foreach (var node in nativeNodeList)
{
nodeList.Add(node);
}
nodeList.Sort();
beginNode.Run();
foreach (var item in nodeList)
{
@@ -209,6 +209,7 @@ namespace StgSharp.Logic
{
try
{
//Console.WriteLine(name);
BlueprintPipeline.WaitAll(inputInterfaces);
mainOperation(in inputInterfaces, in outputInterfaces);
}
@@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.Authentication.ExtendedProtection;
using System.Text;
using System.Threading;
@@ -68,15 +69,14 @@ namespace StgSharp.Logic
public void CompleteAndSkip()
{
Console.WriteLine(Former.Name);
Console.WriteLine($"{former.Name}\t->\t{after.Name}\tComplete");
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
formerCompleteSemaphore.Release();
}
public void CompleteAndWriteData(BlueprintPipelineArgs args)
{
this.args = args;
Console.WriteLine($"{former.Name}\t->\t{after.Name}\tComplete");
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
formerCompleteSemaphore.Release();
}
@@ -112,7 +112,7 @@ namespace StgSharp.Logic
public void WaitForStart()
{
Console.WriteLine($"Waiting\t{former.Name}\t->\t{after.Name}");
//Console.WriteLine($"Waiting \t{former.Name}\t->\t{after.Name}");
formerCompleteSemaphore.Wait();
}
+25 -22
View File
@@ -43,7 +43,7 @@ namespace StgSharp
public class TimeSpanProvider
{
private Action<SemaphoreFullException> _frameUpdateMissCallback = null;
private Action _frameUpdateMissCallback = null;
private readonly int _maxSpanCount;
private Action _refreshCallback;
@@ -108,7 +108,7 @@ namespace StgSharp
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
public Action<SemaphoreFullException> FrameUpdateMissCallback
public Action FrameUpdateMissCallback
{
get => _frameUpdateMissCallback;
set => _frameUpdateMissCallback = value;
@@ -140,30 +140,33 @@ namespace StgSharp
internal bool CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
if (microseconds - _spanBegin < _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
try
return true;
}
_spanBegin = microseconds;
timeSpanCount++;
if (_refreshCallback != null)
{
_refreshCallback();
}
if (_refreshSemaphore.CurrentCount == 0)
{
_refreshSemaphore.Release();
}
else
{
if (_frameUpdateMissCallback != null)
{
if (_refreshCallback != null)
{
_refreshCallback();
}
_refreshSemaphore.Release();
}
catch (SemaphoreFullException ex)
{
if (_frameUpdateMissCallback != null)
{
_frameUpdateMissCallback(ex);
}
}
if (timeSpanCount > _maxSpanCount)
{
return false;
_frameUpdateMissCallback();
}
}
if (timeSpanCount > _maxSpanCount)
{
return false;
}
return true;
}