Daily update on 20250304-070522 by Nitload Youmu. Additional Message : None
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="BlueprintSchedueler.cs"
|
||||
// file="Blueprint.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,27 +28,19 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Blueprint
|
||||
{
|
||||
/// <summary>
|
||||
/// A sets of complex logic designed for running in multi threads environment. Warning: do not
|
||||
/// run a <see cref="BlueprintSchedueler" /> instance in multi threads more than once.
|
||||
/// run a <see cref="BlueprintScheduler" /> instance in multi threads more than once.
|
||||
/// </summary>
|
||||
public partial class BlueprintSchedueler : IConvertableToBlueprintNode
|
||||
public partial class BlueprintScheduler : IConvertableToBlueprintNode
|
||||
{
|
||||
|
||||
private BeginningNode beginNode;
|
||||
@@ -64,7 +56,7 @@ namespace StgSharp.Blueprint
|
||||
internal int currentGlobalNodeIndex;
|
||||
internal int currentNativeNodeIndex;
|
||||
|
||||
public BlueprintSchedueler()
|
||||
public BlueprintScheduler()
|
||||
{
|
||||
allNode = new Dictionary<string, BlueprintNode>();
|
||||
globalNodeList = new List<BlueprintNode>();
|
||||
@@ -78,23 +70,24 @@ namespace StgSharp.Blueprint
|
||||
|
||||
public BlueprintNode EndLayer => endNode;
|
||||
|
||||
public BlueprintNodeOperation Operation
|
||||
{
|
||||
get => ExecuteMain;
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get => runningStat.CurrentCount == 0;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<string> InputInterfacesName
|
||||
public IEnumerable<string> InputInterfacesName
|
||||
{
|
||||
get { return beginNode.OutputInterfaces
|
||||
.Select( p => p.Key )
|
||||
.ToArray(); }
|
||||
get { return beginNode.OutputInterfaces.Keys; }
|
||||
}
|
||||
|
||||
public ReadOnlySpan<string> OutputInterfacesName
|
||||
public IEnumerable<string> OutputInterfacesName
|
||||
{
|
||||
get { return beginNode.OutputInterfaces
|
||||
.Select( p => p.Key )
|
||||
.ToArray(); }
|
||||
get { return beginNode.OutputInterfaces.Keys; }
|
||||
}
|
||||
|
||||
/**/
|
||||
@@ -112,7 +105,6 @@ namespace StgSharp.Blueprint
|
||||
allNode.Add( node.Name, node );
|
||||
}
|
||||
|
||||
|
||||
public void ExecuteMain(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output )
|
||||
@@ -120,11 +112,6 @@ namespace StgSharp.Blueprint
|
||||
BlueprintRunner.Run( this );
|
||||
}
|
||||
|
||||
public BlueprintNodeOperation Operation
|
||||
{
|
||||
get => ExecuteMain;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public (string name, BlueprintPipelineArgs arg)[] GetOutput()
|
||||
{
|
||||
@@ -179,7 +166,7 @@ namespace StgSharp.Blueprint
|
||||
return false;
|
||||
}
|
||||
|
||||
~BlueprintSchedueler()
|
||||
~BlueprintScheduler()
|
||||
{
|
||||
runningStat.Dispose();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Blueprint
|
||||
{
|
||||
public partial class BlueprintSchedueler
|
||||
public partial class BlueprintScheduler
|
||||
{
|
||||
|
||||
public BlueprintNode CreateBlueprintNode(
|
||||
|
||||
@@ -47,32 +47,28 @@ namespace StgSharp.Blueprint
|
||||
public static class BlueprintRunner
|
||||
{
|
||||
|
||||
private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray();
|
||||
private static CancellationTokenSource cts = new CancellationTokenSource();
|
||||
private static ConcurrentStack<BlueprintSchedueler> blueprintInWaiting
|
||||
= new ConcurrentStack<BlueprintSchedueler>();
|
||||
private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray(
|
||||
);
|
||||
private static CancellationTokenSource cts = new CancellationTokenSource(
|
||||
);
|
||||
private static ConcurrentStack<BlueprintScheduler> blueprintInWaiting
|
||||
= new ConcurrentStack<BlueprintScheduler>();
|
||||
private static int _callingThread;
|
||||
private static SemaphoreSlim bpLock = new SemaphoreSlim( 0, 1 );
|
||||
|
||||
private static NodeRunner[] CreateBlueprintRunnerArray()
|
||||
{
|
||||
int count = Environment.ProcessorCount;
|
||||
return new NodeRunner[ count < 2 ? count : count - 2];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only the fallowing occasions of calling are valid:
|
||||
/// 1. no bp is running or the only bp is quitting.
|
||||
/// 2. calling from the main thread and the current running bp.
|
||||
/// Only the fallowing occasions of calling are valid: 1. no bp is running or the only bp is
|
||||
/// quitting. 2. calling from the main thread and the current running bp.
|
||||
/// </summary>
|
||||
internal static bool IsValidCalling
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( NodeRunner.CurrentBlueprint == null ) || //no bp running at all
|
||||
( ( blueprintInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning == false ) ) )
|
||||
// a bp is quiting
|
||||
{
|
||||
( ( blueprintInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning ==
|
||||
false ) ) )
|
||||
// a bp is quiting
|
||||
{
|
||||
//in case no bp is running
|
||||
return true;
|
||||
}
|
||||
@@ -91,7 +87,7 @@ namespace StgSharp.Blueprint
|
||||
}
|
||||
}
|
||||
|
||||
public static void Run(BlueprintSchedueler blueprint)
|
||||
public static void Run( BlueprintScheduler blueprint )
|
||||
{
|
||||
//Console.WriteLine();
|
||||
if( blueprint == null ) {
|
||||
@@ -104,14 +100,13 @@ namespace StgSharp.Blueprint
|
||||
if( IsValidCalling ) {
|
||||
//Console.WriteLine("valid and run");
|
||||
if( InterruptAndRunNewBp( blueprint ) ) {
|
||||
while (InterruptAndRunNewBp(
|
||||
NodeRunner.CurrentBlueprint )){ };
|
||||
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
|
||||
;
|
||||
}
|
||||
} else {
|
||||
bpLock.Wait();
|
||||
if( InterruptAndRunNewBp( blueprint ) ) {
|
||||
while (InterruptAndRunNewBp(
|
||||
NodeRunner.CurrentBlueprint)) { }
|
||||
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
|
||||
}
|
||||
|
||||
bpLock.Release();
|
||||
@@ -141,16 +136,17 @@ namespace StgSharp.Blueprint
|
||||
foreach( NodeRunner task in allAvailableTask ) {
|
||||
task.Cts.Cancel();
|
||||
}
|
||||
foreach( BlueprintSchedueler bp in blueprintInWaiting ) {
|
||||
foreach( BlueprintScheduler bp in blueprintInWaiting ) {
|
||||
bp.Terminate();
|
||||
}
|
||||
blueprintInWaiting.Clear();
|
||||
}
|
||||
|
||||
internal static bool InterruptAndRunNewBp( BlueprintSchedueler newBp )
|
||||
internal static bool InterruptAndRunNewBp( BlueprintScheduler newBp )
|
||||
{
|
||||
Debug.Assert( newBp != null );
|
||||
if( ( newBp != NodeRunner.CurrentBlueprint ) && ( NodeRunner.CurrentBlueprint != null ) ) {
|
||||
if( ( newBp != NodeRunner.CurrentBlueprint ) && ( NodeRunner.CurrentBlueprint !=
|
||||
null ) ) {
|
||||
//if a running bp exists
|
||||
blueprintInWaiting.Push( NodeRunner.CurrentBlueprint );
|
||||
}
|
||||
@@ -162,7 +158,8 @@ namespace StgSharp.Blueprint
|
||||
|
||||
//run beginning node to init it first.
|
||||
if( !NodeRunner.CurrentBlueprint.IsRunning ) {
|
||||
( NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode )!.Run();
|
||||
( NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode )!.Run(
|
||||
);
|
||||
}
|
||||
|
||||
//refresh all tasks
|
||||
@@ -174,7 +171,7 @@ namespace StgSharp.Blueprint
|
||||
}
|
||||
BlueprintNode node;
|
||||
while( !cts.Token.IsCancellationRequested && NodeRunner.CurrentBlueprint
|
||||
.RequestNextNativeNode( out node ) ) {
|
||||
.RequestNextNativeNode( out node ) ) {
|
||||
node.Run();
|
||||
if( !NodeRunner.CurrentBlueprint.IsRunning ) {
|
||||
break;
|
||||
@@ -184,12 +181,18 @@ namespace StgSharp.Blueprint
|
||||
return blueprintInWaiting.TryPeek( out NodeRunner.CurrentBlueprint );
|
||||
}
|
||||
|
||||
private static NodeRunner[] CreateBlueprintRunnerArray()
|
||||
{
|
||||
int count = Environment.ProcessorCount;
|
||||
return new NodeRunner[ count < 2 ? count : count - 2];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class NodeRunner : CancellableTask
|
||||
{
|
||||
|
||||
private static BlueprintSchedueler _current;
|
||||
private static BlueprintScheduler _current;
|
||||
|
||||
internal NodeRunner()
|
||||
: base()
|
||||
@@ -197,7 +200,7 @@ namespace StgSharp.Blueprint
|
||||
_startup = InternalRun;
|
||||
}
|
||||
|
||||
internal static ref BlueprintSchedueler CurrentBlueprint
|
||||
internal static ref BlueprintScheduler CurrentBlueprint
|
||||
{
|
||||
get => ref _current;
|
||||
}
|
||||
|
||||
@@ -40,16 +40,19 @@ namespace StgSharp.Blueprint
|
||||
{
|
||||
public class CrossFrameOperation : IConvertableToBlueprintNode
|
||||
{
|
||||
|
||||
private static string[] _inputName = ["TaskIn"];
|
||||
private static string[] _outputName = ["TaskOut"];
|
||||
private Action _mainExecution;
|
||||
private int currentCount;
|
||||
private readonly int cycleCount;
|
||||
private Action _mainExecution;
|
||||
|
||||
public CrossFrameOperation( Action startup, int cycleCount )
|
||||
{
|
||||
MainExecution = startup;
|
||||
this.cycleCount = ( cycleCount > 1 ) ?
|
||||
cycleCount : throw new ArgumentException(
|
||||
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(BlueprintNode).Name} instead."}" );
|
||||
cycleCount : throw new ArgumentException(
|
||||
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(BlueprintNode).Name} instead."}" );
|
||||
this.cycleCount = cycleCount;
|
||||
currentCount = cycleCount;
|
||||
}
|
||||
@@ -60,17 +63,18 @@ namespace StgSharp.Blueprint
|
||||
private protected set => _mainExecution = value;
|
||||
}
|
||||
|
||||
private static string[] _inputName = ["TaskIn"];
|
||||
private static string[] _outputName = ["TaskOut"];
|
||||
|
||||
public BlueprintNodeOperation Operation
|
||||
{
|
||||
get => ExecuteMain;
|
||||
}
|
||||
|
||||
public IEnumerable<string> InputInterfacesName => _inputName;
|
||||
|
||||
public IEnumerable<string> OutputInterfacesName => _outputName;
|
||||
|
||||
public void ExecuteMain(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output )
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output )
|
||||
{
|
||||
if( currentCount < cycleCount ) {
|
||||
Interlocked.Increment( ref currentCount );
|
||||
@@ -83,9 +87,5 @@ namespace StgSharp.Blueprint
|
||||
BlueprintPipeline.SkipAll( output );
|
||||
}
|
||||
|
||||
public ReadOnlySpan<string> InputInterfacesName => _inputName;
|
||||
|
||||
public ReadOnlySpan<string> OutputInterfacesName => _outputName;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,22 +36,26 @@ using System.Text;
|
||||
namespace StgSharp.Blueprint
|
||||
{
|
||||
public delegate void BlueprintNodeOperation(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output );
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output );
|
||||
|
||||
public interface IConvertableToBlueprintNode
|
||||
{
|
||||
public ReadOnlySpan<string> InputInterfacesName
|
||||
|
||||
BlueprintNodeOperation Operation
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<string> OutputInterfacesName
|
||||
public IEnumerable<string> InputInterfacesName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
BlueprintNodeOperation Operation { get; }
|
||||
public IEnumerable<string> OutputInterfacesName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,9 +67,9 @@ namespace StgSharp.Blueprint
|
||||
private BlueprintNodeOperation _execution;
|
||||
|
||||
public DefaultConvertableToBlueprintNode(
|
||||
BlueprintNodeOperation execution,
|
||||
string[] input,
|
||||
string[] output )
|
||||
BlueprintNodeOperation execution,
|
||||
string[] input,
|
||||
string[] output )
|
||||
{
|
||||
_input = input;
|
||||
_output = output;
|
||||
@@ -74,9 +78,9 @@ namespace StgSharp.Blueprint
|
||||
|
||||
public BlueprintNodeOperation Operation => _execution;
|
||||
|
||||
public ReadOnlySpan<string> InputInterfacesName => _input;
|
||||
public IEnumerable<string> InputInterfacesName => _input;
|
||||
|
||||
public ReadOnlySpan<string> OutputInterfacesName => _output;
|
||||
public IEnumerable<string> OutputInterfacesName => _output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,12 @@ namespace StgSharp.Blueprint
|
||||
internal sealed class BeginningNode : BlueprintNode
|
||||
{
|
||||
|
||||
private BlueprintSchedueler _bp;
|
||||
private BlueprintScheduler _bp;
|
||||
|
||||
public BeginningNode( BlueprintSchedueler bp )
|
||||
: base(DefaultOperation, name: "BeginningNode", true, ["default"], ["default"] )
|
||||
public BeginningNode( BlueprintScheduler bp )
|
||||
: base(
|
||||
DefaultOperation, name: "BeginningNode", true, ["default"],
|
||||
["default"] )
|
||||
{
|
||||
_bp = bp;
|
||||
}
|
||||
@@ -70,8 +72,8 @@ namespace StgSharp.Blueprint
|
||||
}
|
||||
|
||||
public new void SetCertainOutputPort(
|
||||
string name,
|
||||
BlueprintPipeline pipeline )
|
||||
string name,
|
||||
BlueprintPipeline pipeline )
|
||||
{
|
||||
if( _outputInterfaces.ContainsKey( name ) ) {
|
||||
_outputInterfaces[ name ] = pipeline;
|
||||
@@ -84,10 +86,12 @@ namespace StgSharp.Blueprint
|
||||
internal sealed class EndingNode : BlueprintNode
|
||||
{
|
||||
|
||||
private BlueprintSchedueler _bp;
|
||||
private BlueprintScheduler _bp;
|
||||
|
||||
public EndingNode( BlueprintSchedueler bp )
|
||||
: base(DefaultOperation, name: "EndingNode", true, ["default"], ["default"] )
|
||||
public EndingNode( BlueprintScheduler bp )
|
||||
: base(
|
||||
DefaultOperation, name: "EndingNode", true, ["default"],
|
||||
["default"] )
|
||||
{
|
||||
_bp = bp;
|
||||
}
|
||||
@@ -96,7 +100,7 @@ namespace StgSharp.Blueprint
|
||||
{
|
||||
get { return InputInterfaces.Select(
|
||||
key => (key.Key, key.Value.Args) )
|
||||
.ToArray(); }
|
||||
.ToArray(); }
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
@@ -108,8 +112,8 @@ namespace StgSharp.Blueprint
|
||||
}
|
||||
|
||||
public new void SetCertainInputPort(
|
||||
string name,
|
||||
BlueprintPipeline pipeline )
|
||||
string name,
|
||||
BlueprintPipeline pipeline )
|
||||
{
|
||||
if( _inputInterfaces.ContainsKey( name ) ) {
|
||||
_inputInterfaces[ name ] = pipeline;
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+83bde12d2227bf32a3b939e94849bbd7273bad21")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+825e68853cd1738287eecc8a4390ee9c78550308")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/83bde12d2227bf32a3b939e94849bbd7273bad21/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/825e68853cd1738287eecc8a4390ee9c78550308/*"}}
|
||||
Reference in New Issue
Block a user