Daily update on 20250420-041137 by Nitload Youmu. Additional Message : Change: pipeline nodes use port to connect instead of connctors, this make send to multi-ports and recieve from multi-ports possible.

Remove: Some types in Pipeline namepace removed sueto no need for connectors

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-04-20 04:11:37 +08:00
parent c29993fd84
commit b618fdf7b5
72 changed files with 1343 additions and 602 deletions
+12 -4
View File
@@ -39,7 +39,7 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class TexturePipeline : PipeLineConnectorArgs
public class TexturePipeline : IPipeLineConnectionPayload
{
private Image _value;
@@ -49,11 +49,19 @@ namespace StgSharp.Graphics
_value = i;
}
public new Image Value
public object? ValueDefault => null;
public object Value
{
get => _value;
set => _value = value ??
throw new ArgumentNullException( nameof( value ) );
set
{
ArgumentNullException.ThrowIfNull( value );
if( value is not Image image ) {
throw new ArgumentException( "Value must be of type Image" );
}
_value = image;
}
}
}
@@ -52,7 +52,7 @@ namespace StgSharp.PipeLine
MainExecution = startup;
this.cycleCount = ( cycleCount > 1 ) ?
cycleCount : throw new ArgumentException(
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(PipeLineNode).Name} instead."}" );
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(PipelineNode).Name} instead."}" );
this.cycleCount = cycleCount;
currentCount = cycleCount;
}
@@ -63,28 +63,30 @@ namespace StgSharp.PipeLine
private protected set => _mainExecution = value;
}
public BlueprintNodeOperation Operation
{
get => ExecuteMain;
}
public IEnumerable<string> InputInterfacesName => _inputName;
public IEnumerable<string> OutputInterfacesName => _outputName;
public void ExecuteMain(
in Dictionary<string, PipelineConnector> input,
in Dictionary<string, PipelineConnector> output )
public PipelineNodeOperation Operation
{
if( currentCount < cycleCount ) {
get => NodeMain;
}
public void NodeMain(
in Dictionary<string, PipelineNodeImport> input,
in Dictionary<string, PipelineNodeExport> output )
{
if( currentCount < cycleCount )
{
Interlocked.Increment( ref currentCount );
} else {
} else
{
Interlocked.Exchange( ref currentCount, 0 );
Task.Run( MainExecution );
}
//Console.WriteLine(currentCount);
PipelineConnector.SkipAll( output );
PipelineNodeExport.SkipAll( output );
}
}
@@ -35,27 +35,22 @@ using System.Text;
namespace StgSharp.PipeLine
{
public delegate void BlueprintNodeOperation(
in Dictionary<string, PipelineConnector> input,
in Dictionary<string, PipelineConnector> output );
public delegate void PipelineNodeOperation(
in Dictionary<string, PipelineNodeImport> input,
in Dictionary<string, PipelineNodeExport> output );
public interface IConvertableToBlueprintNode
{
BlueprintNodeOperation Operation
{
get;
}
PipelineNodeOperation Operation { get; }
public IEnumerable<string> InputInterfacesName
{
get;
}
public IEnumerable<string> InputInterfacesName { get; }
public IEnumerable<string> OutputInterfacesName
{
get;
}
public IEnumerable<string> OutputInterfacesName { get; }
void NodeMain(
in Dictionary<string, PipelineNodeImport> input,
in Dictionary<string, PipelineNodeExport> output );
}
@@ -64,23 +59,30 @@ namespace StgSharp.PipeLine
private string[] _input;
private string[] _output;
private BlueprintNodeOperation _execution;
private PipelineNodeOperation _execution;
public DefaultConvertableToBlueprintNode(
BlueprintNodeOperation execution,
string[] input,
string[] output )
PipelineNodeOperation execution,
string[] input,
string[] output )
{
_input = input;
_output = output;
_execution = execution;
}
public BlueprintNodeOperation Operation => _execution;
public PipelineNodeOperation Operation => _execution;
public IEnumerable<string> InputInterfacesName => _input;
public IEnumerable<string> OutputInterfacesName => _output;
public void NodeMain(
in Dictionary<string, PipelineNodeImport> input,
in Dictionary<string, PipelineNodeExport> output )
{
_execution.Invoke( input, output );
}
}
}
+56 -41
View File
@@ -46,19 +46,17 @@ namespace StgSharp.PipeLine
public static class PipeLineRunner
{
private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray(
);
private static CancellationTokenSource cts = new CancellationTokenSource(
);
private static ConcurrentStack<BlueprintScheduler> blueprintInWaiting
= new ConcurrentStack<BlueprintScheduler>();
private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray();
private static CancellationTokenSource cts = new CancellationTokenSource();
private static ConcurrentStack<PipelineScheduler> blueprintInWaiting
= new ConcurrentStack<PipelineScheduler>();
private static int _callingThread;
private static SemaphoreSlim bpLock = new SemaphoreSlim( 0, 1 );
/// <summary>
/// <para> Only the following occasions of calling are valid: </para> <para> 1. no bp is
/// running or the only bp is quitting. </para><para> 2. calling from the main thread or a
/// thread the current bp is running on.</para>
/// <para> Only the following occasions of calling are valid: </para> <para>1. no bp is
/// running or the only bp is quitting.</para><para>2. calling from the main thread or a
/// thread the current bp is running on. </para>
/// </summary>
internal static bool IsValidCalling
{
@@ -66,18 +64,22 @@ namespace StgSharp.PipeLine
{
if( ( NodeRunner.CurrentBlueprint == null ) || //no bp running at all
( ( blueprintInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning ==
false ) ) ) {
false ) ) )
{
// a bp is quitting
//in case no bp is running
return true;
}
int? id = Task.CurrentId;
if( id is null ) {
if( id is null )
{
// in case calling from main thread and current running bp
return _callingThread == Environment.CurrentManagedThreadId;
}
foreach( NodeRunner item in allAvailableTask ) {
if( item.Id == id ) {
foreach( NodeRunner item in allAvailableTask )
{
if( item.Id == id )
{
//if calling from any bp running task
return true;
}
@@ -86,25 +88,29 @@ namespace StgSharp.PipeLine
}
}
public static void Run( BlueprintScheduler blueprint )
public static void Run( PipelineScheduler blueprint )
{
//Console.WriteLine();
if( blueprint == null ) {
if( blueprint == null )
{
return;
}
if( blueprint.IsRunning ) {
throw new InvalidOperationException(
"Attempt to run a blueprint instance twice." );
throw new InvalidOperationException( "Attempt to run a blueprint instance twice." );
}
if( IsValidCalling ) {
if( IsValidCalling )
{
//Console.WriteLine("valid and run");
if( InterruptAndRunNewBp( blueprint ) ) {
if( InterruptAndRunNewBp( blueprint ) )
{
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
;
}
} else {
} else
{
bpLock.Wait();
if( InterruptAndRunNewBp( blueprint ) ) {
if( InterruptAndRunNewBp( blueprint ) )
{
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
}
@@ -118,8 +124,10 @@ namespace StgSharp.PipeLine
if( size < 1 ) {
size = 1;
}
if( allAvailableTask.Length >= size ) {
for( int i = size; i < allAvailableTask.Length; i++ ) {
if( allAvailableTask.Length >= size )
{
for( int i = size; i < allAvailableTask.Length; i++ )
{
if( allAvailableTask[ i ] != null ) {
allAvailableTask[ i ].Cancel();
}
@@ -135,44 +143,47 @@ namespace StgSharp.PipeLine
foreach( NodeRunner task in allAvailableTask ) {
task.Cts.Cancel();
}
foreach( BlueprintScheduler bp in blueprintInWaiting ) {
foreach( PipelineScheduler bp in blueprintInWaiting ) {
bp.Terminate();
}
blueprintInWaiting.Clear();
}
internal static bool InterruptAndRunNewBp( BlueprintScheduler newBp )
internal static bool InterruptAndRunNewBp( PipelineScheduler 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 );
}
//load new bp to current bp
Interlocked.Exchange( ref NodeRunner.CurrentBlueprint!, newBp );
Interlocked.Exchange(
ref _callingThread, Environment.CurrentManagedThreadId );
Interlocked.Exchange( ref _callingThread, Environment.CurrentManagedThreadId );
//run beginning node to init it first.
if( !NodeRunner.CurrentBlueprint.IsRunning ) {
( NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode )!.Run(
);
if( !NodeRunner.CurrentBlueprint.IsRunning )
{
( NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode )!.Run();
}
//refresh all tasks
for( int i = 0; i < allAvailableTask.Length; i++ ) {
for( int i = 0; i < allAvailableTask.Length; i++ )
{
NodeRunner item = allAvailableTask[ i ];
if( ( item is null ) || item.IsCompleted ) {
allAvailableTask[ i ] = NodeRunner.Run();
}
}
PipeLineNode node;
PipelineNode node;
while( !cts.Token.IsCancellationRequested && NodeRunner.CurrentBlueprint
.RequestNextNativeNode( out node ) ) {
.RequestNextNativeNode(
out node ) )
{
node.Run();
if( !NodeRunner.CurrentBlueprint.IsRunning ) {
if( !NodeRunner.CurrentBlueprint.IsRunning )
{
break;
}
}
@@ -191,7 +202,7 @@ namespace StgSharp.PipeLine
internal class NodeRunner : CancellableTask
{
private static BlueprintScheduler _current;
private static PipelineScheduler _current;
internal NodeRunner()
: base()
@@ -199,14 +210,17 @@ namespace StgSharp.PipeLine
_startup = InternalRun;
}
internal static ref BlueprintScheduler CurrentBlueprint
internal static ref PipelineScheduler CurrentBlueprint
{
get => ref _current;
}
internal static NodeRunner Run()
{
NodeRunner ret = new NodeRunner { _startup = InternalRun };
NodeRunner ret = new NodeRunner
{
_startup = InternalRun
};
ret._internalTask = Task.Run( ret.InternalAction );
return ret;
}
@@ -214,9 +228,10 @@ namespace StgSharp.PipeLine
private static void InternalRun( CancellationToken token )
{
//Console.WriteLine("Task Begin");
PipeLineNode item;
PipelineNode item;
while( ( CurrentBlueprint != null ) && CurrentBlueprint.IsRunning && !token.IsCancellationRequested && CurrentBlueprint.RequestNexGlobalNode(
out item ) ) {
out item ) )
{
//Console.WriteLine($"Get node of {item.Name}, going to run.");
item.Run();
}
@@ -0,0 +1,157 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PipelineNodePort.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.PipeLine
{
public class PipelineNodeExport
{
private HashSet<PipelineNodeImport> _linkerSet = new HashSet<PipelineNodeImport>();
private SemaphoreSlim formerCompleteSemaphore;
public PipelineNodeExport( PipelineNode container, string name )
{
Container = container;
Name = name;
formerCompleteSemaphore = new SemaphoreSlim( initialCount: 0, maxCount: 1 );
}
public PipelineNode Container { get; init; }
public SemaphoreSlim Waiter { get; init; }
public string Name { get; init; }
public void Connect( PipelineNodeImport port )
{
ArgumentNullException.ThrowIfNull( port );
if( _linkerSet.Add( port ) ) {
Container.Next.Add( port.Container );
}
}
public static void SkipAll( Dictionary<string, PipelineNodeExport> ports )
{
if( ports is null ) {
return;
}
foreach( PipelineNodeExport port in ports.Values ) {
port.Waiter.Release();
}
}
public void TransmitValue( IPipeLineConnectionPayload value )
{
foreach( PipelineNodeImport item in _linkerSet ) { }
}
public void WaitAll( IEnumerable<PipelineNodeExport> ports )
{
if( ports is null ) {
return;
}
foreach( PipelineNodeExport port in ports ) {
port.Waiter.Wait();
}
}
}
public class PipelineNodeImport
{
private HashSet<PipelineNodeExport> _linkerSet = new HashSet<PipelineNodeExport>();
public PipelineNodeImport( PipelineNode container, string name )
{
Container = container;
Name = name;
}
public IEnumerable<PipelineNodeExport> LinkedPorts => _linkerSet;
public PipelineNode Container { get; init; }
public SemaphoreSlim Waiter { get; init; }
public string Name { get; init; }
public void Connect( PipelineNodeExport port )
{
ArgumentNullException.ThrowIfNull( port );
if( _linkerSet.Add( port ) ) {
Container.Previous.Add( port.Container );
}
}
public IEnumerator<PipelineNode> GetFormerNodes()
{
foreach( PipelineNodeExport port in _linkerSet ) {
yield return port.Container;
}
}
public void Wait()
{
foreach( PipelineNodeExport connector in _linkerSet ) {
connector.Waiter.Wait();
}
}
public static void WaitAll( IDictionary<string, PipelineNodeImport> ports )
{
if( ports is null ) {
return;
}
foreach( PipelineNodeImport port in ports.Values ) {
port.Wait();
}
}
public static void WaitAll( IEnumerable<PipelineNodeImport> ports )
{
if( ports is null ) {
return;
}
foreach( PipelineNodeImport port in ports ) {
port.Wait();
}
}
}
}
@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PipelineScheduler.NodeCraeater.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.PipeLine
{
public partial class PipelineScheduler
{
public PipelineNode CreateBlueprintNode(
string name,
PipelineNodeOperation operation,
string[] inputPort,
string[] outputPort,
bool isNative )
{
PipelineNode node = new PipelineNode( operation, name, isNative, inputPort,
outputPort );
if( isNative )
{
mainThreadNodeList.Add( node );
} else
{
globalNodeList.Add( node );
}
return node;
}
}
}
@@ -0,0 +1,230 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PipelineScheduler.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Stg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
namespace StgSharp.PipeLine
{
/// <summary>
/// A sets of complex logic designed for running in multi threads environment. Warning: do not
/// run a <see cref="PipelineScheduler" /> instance in multi threads more than once.
/// </summary>
public partial class PipelineScheduler : IConvertableToBlueprintNode
{
private BeginningNode _beginning;
private Dictionary<string, PipelineNode> allNode;
private EndingNode _ending;
private List<PipelineNode>
_concurrentNodes = new List<PipelineNode>(),
_mainThreadNodes = new List<PipelineNode>();
private List<PipelineNode> globalNodeList;
private List<PipelineNode> mainThreadNodeList;
private SemaphoreSlim runningStat;
internal int currentGlobalNodeIndex;
internal int currentNativeNodeIndex;
public PipelineScheduler()
{
allNode = new Dictionary<string, PipelineNode>();
globalNodeList = new List<PipelineNode>();
mainThreadNodeList = new List<PipelineNode>();
runningStat = new SemaphoreSlim( 1, 1 );
_beginning = new BeginningNode( this );
_ending = new EndingNode( this );
}
public bool IsRunning
{
get => runningStat.CurrentCount == 0;
}
public IEnumerable<string> InputInterfacesName
{
get { return _beginning.OutputPorts.Keys; }
}
public IEnumerable<string> OutputInterfacesName
{
get { return _beginning.OutputPorts.Keys; }
}
public PipelineNode BeginLayer => _beginning;
public PipelineNode EndLayer => _ending;
public PipelineNodeOperation Operation
{
get => ( this as IConvertableToBlueprintNode ).NodeMain;
}
/**/
internal SemaphoreSlim RunningStat
{
get => runningStat;
}
/**/
public void AddNode( PipelineNode node, bool isNative )
{
ArgumentNullException.ThrowIfNull( node );
node.IsNative = isNative;
allNode.Add( node.Name, node );
}
public void ArrangeNodeOrder()
{
LinkedList<PipelineNode> _cache = new LinkedList<PipelineNode>();
foreach( PipelineNode node in _beginning.Next )
{
if( node.IsNative )
{
_mainThreadNodes.Add( node );
} else
{
_concurrentNodes.Add( node );
}
foreach( PipelineNode item in node.Next )
{
item.Previous.Remove( node );
_cache.AddLast( item );
}
}
while( _cache.Count > 0 )
{
LinkedListNode<PipelineNode> begin = _cache.First!,current = begin,zero;
do
{
PipelineNode node = current.Value;
if( current.Value.Previous.Count == 0 )
{
zero = current;
current = current.Next!;
if( node.IsNative )
{
_mainThreadNodes.Add( node );
} else
{
_concurrentNodes.Add( node );
}
foreach( PipelineNode item in node.Next )
{
item.Previous.Remove( node );
_cache.AddLast( item );
}
_cache.Remove( zero );
} else
{
current = current.Next!;
}
} while (current.Next != begin);
}
}
public void Init()
{
foreach( KeyValuePair<string, PipelineNode> item in allNode )
{
if( item.Value.IsNative )
{
mainThreadNodeList.Add( item.Value );
} else
{
globalNodeList.Add( item.Value );
}
}
mainThreadNodeList.Sort();
globalNodeList.Sort();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void SetInput( params (string name, IPipeLineConnectionPayload arg)[] parameters )
{
_beginning.SetInputData( parameters );
}
public void Terminate()
{
Interlocked.Exchange( ref currentGlobalNodeIndex, int.MaxValue );
Interlocked.Exchange( ref currentNativeNodeIndex, int.MaxValue );
}
internal bool RequestNexGlobalNode( out PipelineNode node )
{
if( currentGlobalNodeIndex < globalNodeList.Count )
{
node = globalNodeList[ currentGlobalNodeIndex ];
Interlocked.Increment( ref currentGlobalNodeIndex );
return true;
}
node = default!;
return false;
}
internal bool RequestNextNativeNode( out PipelineNode node )
{
if( currentNativeNodeIndex < mainThreadNodeList.Count )
{
node = mainThreadNodeList[ currentNativeNodeIndex ];
Interlocked.Increment( ref currentNativeNodeIndex );
return true;
}
node = default!;
return false;
}
void IConvertableToBlueprintNode.NodeMain(
in Dictionary<string, PipelineNodeImport> input,
in Dictionary<string, PipelineNodeExport> output )
{
PipeLineRunner.Run( this );
PipelineNodeExport.SkipAll( output );
}
~PipelineScheduler()
{
runningStat.Dispose();
}
}
}
+126
View File
@@ -0,0 +1,126 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PortArgs.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Security.Authentication.ExtendedProtection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.PipeLine
{
public class PipelineConnector
{
private protected IPipeLineConnectionPayload args;
private protected PipelineNodeExport input;
private protected PipelineNodeImport output;
private protected SemaphoreSlim formerCompleteSemaphore;
public PipelineConnector( PipelineNodeExport former, PipelineNodeImport after )
{
this.input = former;
this.output = after;
formerCompleteSemaphore = new SemaphoreSlim( initialCount: 0, maxCount: 1 );
}
public IPipeLineConnectionPayload Args
{
get => args;
set => args = value;
}
public PipelineNodeExport Input => input;
public PipelineNodeImport Output => output;
public static void SkipAll( Dictionary<string, PipelineConnector> ports )
{
if( ports == null ) {
return;
}
foreach( KeyValuePair<string, PipelineConnector> item in ports )
{
if( item.Value != null ) {
item.Value.CompleteAndSkip();
}
}
}
public static void WaitAll( Dictionary<string, PipelineConnector> ports )
{
if( ports == null ) {
return;
}
foreach( KeyValuePair<string, PipelineConnector> item in ports )
{
if( item.Value != null ) {
item.Value.WaitForStart();
}
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public virtual void WaitForStart()
{
//Console.WriteLine($"Waiting \t{input.ContextName}\t->\t{output.ContextName}");
formerCompleteSemaphore.Wait();
}
~PipelineConnector()
{
formerCompleteSemaphore.Dispose();
}
#region pipline op
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void CompleteAndSkip()
{
//Console.WriteLine($"Complete\t{input.Name}\t->\t{output.Name}");
formerCompleteSemaphore.Release();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void CompleteAndWriteData( IPipeLineConnectionPayload args )
{
this.args = args;
CompleteAndSkip();
}
#endregion
}
public abstract class IPipeLineConnectionPayload { }
}
+17 -50
View File
@@ -33,93 +33,60 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.PipeLine
{
internal sealed class BeginningNode : PipeLineNode
internal sealed class BeginningNode : PipelineNode
{
private BlueprintScheduler _bp;
private PipelineScheduler _bp;
public BeginningNode( BlueprintScheduler bp )
: base(
DefaultOperation, name: "BeginningNode", true, ["default"],
["default"] )
public BeginningNode( PipelineScheduler bp )
: base( DefaultOperation, name: "BeginningNode", true, ["default"], ["default"] )
{
_bp = bp;
}
internal (string name, PipeLineConnectorArgs arg)[] InputData
{
set
{
if( value == null ) {
return;
}
foreach( (string name, PipeLineConnectorArgs arg) parameter in value ) {
OutputInterfaces[ parameter.name ].Args = parameter.arg;
}
}
}
public override void Run()
{
_bp.RunningStat.Wait();
PipelineConnector.SkipAll( _outputInterfaces );
PipelineNodeExport.SkipAll( _output );
}
public new void SetCertainOutputPort(
string name,
PipelineConnector pipeline )
internal void SetInputData( IEnumerable<(string, IPipeLineConnectionPayload)> data )
{
if( _outputInterfaces.ContainsKey( name ) ) {
_outputInterfaces[ name ] = pipeline;
if( data is null ) {
return;
}
foreach( (string, IPipeLineConnectionPayload) item in data ) {
OutputPorts[ item.Item1 ].TransmitValue( item.Item2 );
}
_outputInterfaces.Add( name, pipeline );
}
}
internal sealed class EndingNode : PipeLineNode
internal sealed class EndingNode : PipelineNode
{
private BlueprintScheduler _bp;
private PipelineScheduler _bp;
public EndingNode( BlueprintScheduler bp )
: base(
DefaultOperation, name: "EndingNode", true, ["default"],
["default"] )
public EndingNode( PipelineScheduler bp )
: base( DefaultOperation, name: "EndingNode", true, ["default"], ["default"] )
{
_bp = bp;
}
internal (string name, PipeLineConnectorArgs arg)[] OutputData
{
get { return InputInterfaces.Select(
key => (key.Key, key.Value.Args) )
.ToArray(); }
}
public override void Run()
{
PipelineConnector.WaitAll( _inputInterfaces );
PipelineNodeImport.WaitAll( _input );
Interlocked.Exchange( ref _bp.currentGlobalNodeIndex, 0 );
Interlocked.Exchange( ref _bp.currentNativeNodeIndex, 0 );
_bp.RunningStat.Release();
}
public new void SetCertainInputPort(
string name,
PipelineConnector pipeline )
{
if( _inputInterfaces.ContainsKey( name ) ) {
_inputInterfaces[ name ] = pipeline;
}
_inputInterfaces.Add( name, pipeline );
}
}
}
+3 -12
View File
@@ -39,10 +39,7 @@ namespace StgSharp
public interface IStateMachine<T> where T: Enum
{
public T LastStableState
{
get;
}
public T LastStableState { get; }
public bool TryEnterState();
@@ -56,15 +53,9 @@ namespace StgSharp
where TState: Enum
{
public bool IsInStabelState
{
get;
}
public bool IsInStabelState { get; }
public TState NextStableState
{
get;
}
public TState NextStableState { get; }
public bool TrySwitchState();
-4
View File
@@ -83,10 +83,6 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Logic\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target>
@@ -27,7 +27,6 @@
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"D:\\Programmer\\NugetLocal": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
-1
View File
@@ -151,7 +151,6 @@
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"D:\\Programmer\\NugetLocal": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
@@ -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+2692495dc8460e1f60a2d073f162c5f526e1ba1b")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90")]
[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/2692495dc8460e1f60a2d073f162c5f526e1ba1b/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90/*"}}