code clean up
This commit is contained in:
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="CrossFramePipelineNode.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CrossFramePipelineNode"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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.PipeLine;
|
||||
|
||||
using System;
|
||||
@@ -41,18 +38,19 @@ namespace StgSharp.PipeLine
|
||||
public class CrossFrameOperation : IConvertableToPipelineNode
|
||||
{
|
||||
|
||||
private static string[] _inputName = ["TaskIn"];
|
||||
private static string[] _outputName = ["TaskOut"];
|
||||
private static string[] _inputName = [ "TaskIn" ];
|
||||
private static string[] _outputName = [ "TaskOut" ];
|
||||
private Action _mainExecution;
|
||||
private int currentCount;
|
||||
private readonly int cycleCount;
|
||||
|
||||
public CrossFrameOperation( Action startup, int cycleCount )
|
||||
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(PipelineNode).Name} instead."}" );
|
||||
this.cycleCount = (cycleCount > 1) ?
|
||||
cycleCount :
|
||||
throw new ArgumentException(
|
||||
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(PipelineNode).Name} instead."}");
|
||||
this.cycleCount = cycleCount;
|
||||
currentCount = cycleCount;
|
||||
}
|
||||
@@ -74,19 +72,19 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public void NodeMain(
|
||||
in Dictionary<string, PipelineNodeInPort> input,
|
||||
in Dictionary<string, PipelineNodeOutPort> output )
|
||||
in Dictionary<string, PipelineNodeOutPort> output)
|
||||
{
|
||||
if( currentCount < cycleCount )
|
||||
if (currentCount < cycleCount)
|
||||
{
|
||||
Interlocked.Increment( ref currentCount );
|
||||
Interlocked.Increment(ref currentCount);
|
||||
} else
|
||||
{
|
||||
Interlocked.Exchange( ref currentCount, 0 );
|
||||
Task.Run( MainExecution );
|
||||
Interlocked.Exchange(ref currentCount, 0);
|
||||
Task.Run(MainExecution);
|
||||
}
|
||||
|
||||
//Console.WriteLine(currentCount);
|
||||
PipelineNodeOutPort.SkipAll( output );
|
||||
// Console.WriteLine(currentCount);
|
||||
PipelineNodeOutPort.SkipAll(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IConvertableToPipelineNode.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IConvertableToPipelineNode"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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.Runtime.CompilerServices;
|
||||
@@ -37,7 +34,7 @@ namespace StgSharp.PipeLine
|
||||
{
|
||||
public delegate void PipelineNodeOperation(
|
||||
in Dictionary<string, PipelineNodeInPort> input,
|
||||
in Dictionary<string, PipelineNodeOutPort> output );
|
||||
in Dictionary<string, PipelineNodeOutPort> output);
|
||||
|
||||
public interface IConvertableToPipelineNode
|
||||
{
|
||||
@@ -50,7 +47,7 @@ namespace StgSharp.PipeLine
|
||||
|
||||
void NodeMain(
|
||||
in Dictionary<string, PipelineNodeInPort> input,
|
||||
in Dictionary<string, PipelineNodeOutPort> output );
|
||||
in Dictionary<string, PipelineNodeOutPort> output);
|
||||
|
||||
}
|
||||
|
||||
@@ -61,10 +58,7 @@ namespace StgSharp.PipeLine
|
||||
private string[] _output;
|
||||
private PipelineNodeOperation _execution;
|
||||
|
||||
public DefaultConvertableToBlueprintNode(
|
||||
PipelineNodeOperation execution,
|
||||
string[] input,
|
||||
string[] output )
|
||||
public DefaultConvertableToBlueprintNode(PipelineNodeOperation execution, string[] input, string[] output)
|
||||
{
|
||||
_input = input;
|
||||
_output = output;
|
||||
@@ -79,9 +73,9 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public void NodeMain(
|
||||
in Dictionary<string, PipelineNodeInPort> input,
|
||||
in Dictionary<string, PipelineNodeOutPort> output )
|
||||
in Dictionary<string, PipelineNodeOutPort> output)
|
||||
{
|
||||
_execution.Invoke( input, output );
|
||||
_execution.Invoke(input, output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PipeLineRunner.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipeLineRunner"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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.Threading;
|
||||
|
||||
using System;
|
||||
@@ -51,83 +48,82 @@ namespace StgSharp.PipeLine
|
||||
private static ConcurrentStack<PipelineScheduler> pipelineInWaiting
|
||||
= new ConcurrentStack<PipelineScheduler>();
|
||||
private static int _callingThread;
|
||||
private static SemaphoreSlim pipelineLock = new SemaphoreSlim( 0, 1 );
|
||||
private static SemaphoreSlim pipelineLock = new SemaphoreSlim(0, 1);
|
||||
|
||||
public static void Run( PipelineScheduler pipeline )
|
||||
public static void Run(PipelineScheduler pipeline)
|
||||
{
|
||||
//Console.WriteLine();
|
||||
if( pipeline == null )
|
||||
// Console.WriteLine();
|
||||
if (pipeline == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( pipeline.IsRunning ) {
|
||||
throw new InvalidOperationException( "Attempt to run a blueprint instance twice." );
|
||||
if (pipeline.IsRunning) {
|
||||
throw new InvalidOperationException("Attempt to run a blueprint instance twice.");
|
||||
}
|
||||
if( !IsValidCalling() ) {
|
||||
if (!IsValidCalling()) {
|
||||
pipelineLock.Wait();
|
||||
}
|
||||
if( InterruptAndRunNewPipeline( pipeline ) )
|
||||
if (InterruptAndRunNewPipeline(pipeline))
|
||||
{
|
||||
while( InterruptAndRunNewPipeline( NodeRunner.CurrentPipeline! ) ) { }
|
||||
while (InterruptAndRunNewPipeline(NodeRunner.CurrentPipeline!)) { }
|
||||
}
|
||||
pipelineLock.Release();
|
||||
Interlocked.Exchange( ref _callingThread, -1 );
|
||||
Interlocked.Exchange(ref _callingThread, -1);
|
||||
}
|
||||
|
||||
public static void SetMaxTaskCount( int size )
|
||||
public static void SetMaxTaskCount(int size)
|
||||
{
|
||||
if( size < 1 ) {
|
||||
if (size < 1) {
|
||||
size = 1;
|
||||
}
|
||||
if( allAvailableTask.Length >= size )
|
||||
if (allAvailableTask.Length >= size)
|
||||
{
|
||||
for( int i = size; i < allAvailableTask.Length; i++ )
|
||||
for (int i = size; i < allAvailableTask.Length; i++)
|
||||
{
|
||||
if( allAvailableTask[ i ] != null ) {
|
||||
allAvailableTask[ i ].Cancel();
|
||||
if (allAvailableTask[i] != null) {
|
||||
allAvailableTask[i].Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Array.Resize( ref allAvailableTask, size );
|
||||
Array.Resize(ref allAvailableTask, size);
|
||||
}
|
||||
|
||||
public static void Terminate()
|
||||
{
|
||||
cts.Cancel();
|
||||
if( NodeRunner.CurrentPipeline is null ) {
|
||||
if (NodeRunner.CurrentPipeline is null) {
|
||||
return;
|
||||
}
|
||||
NodeRunner.CurrentPipeline.Terminate();
|
||||
foreach( NodeRunner task in allAvailableTask ) {
|
||||
foreach (NodeRunner task in allAvailableTask) {
|
||||
task.Cts.Cancel();
|
||||
}
|
||||
foreach( PipelineScheduler bp in pipelineInWaiting ) {
|
||||
foreach (PipelineScheduler bp in pipelineInWaiting) {
|
||||
bp.Terminate();
|
||||
}
|
||||
pipelineInWaiting.Clear();
|
||||
}
|
||||
|
||||
internal static bool InterruptAndRunNewPipeline( PipelineScheduler newPipeline )
|
||||
internal static bool InterruptAndRunNewPipeline(PipelineScheduler newPipeline)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( newPipeline );
|
||||
if( ( newPipeline != NodeRunner.CurrentPipeline ) &&
|
||||
( NodeRunner.CurrentPipeline != null ) )
|
||||
ArgumentNullException.ThrowIfNull(newPipeline);
|
||||
if ((newPipeline != NodeRunner.CurrentPipeline) && (NodeRunner.CurrentPipeline != null))
|
||||
{
|
||||
//if a running bp exists
|
||||
pipelineInWaiting.Push( NodeRunner.CurrentPipeline );
|
||||
// if a running bp exists
|
||||
pipelineInWaiting.Push(NodeRunner.CurrentPipeline);
|
||||
}
|
||||
|
||||
//load new bp to current bp
|
||||
// load new bp to current bp
|
||||
NodeRunner.CurrentPipeline = newPipeline;
|
||||
Interlocked.Exchange( ref _callingThread, Environment.CurrentManagedThreadId );
|
||||
Interlocked.Exchange(ref _callingThread, Environment.CurrentManagedThreadId);
|
||||
|
||||
//run beginning node to init it first.
|
||||
if( !NodeRunner.CurrentPipeline.IsRunning )
|
||||
// run beginning node to init it first.
|
||||
if (!NodeRunner.CurrentPipeline.IsRunning)
|
||||
{
|
||||
( NodeRunner.CurrentPipeline.BeginLayer as BeginningNode )!.Run();
|
||||
(NodeRunner.CurrentPipeline.BeginLayer as BeginningNode)!.Run();
|
||||
}
|
||||
|
||||
//refresh all tasks
|
||||
// refresh all tasks
|
||||
/*
|
||||
for( int i = 0; i < allAvailableTask.Length; i++ )
|
||||
{
|
||||
@@ -138,58 +134,57 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
/**/
|
||||
PipelineNode node;
|
||||
while( !cts.Token.IsCancellationRequested &&
|
||||
NodeRunner.CurrentPipeline.RequestNextMainThreadNode( out node ) )
|
||||
while (!cts.Token.IsCancellationRequested && NodeRunner.CurrentPipeline.RequestNextMainThreadNode(out node))
|
||||
{
|
||||
node.Run();
|
||||
if( !NodeRunner.CurrentPipeline.IsRunning )
|
||||
if (!NodeRunner.CurrentPipeline.IsRunning)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while( ( NodeRunner.CurrentPipeline != null ) &&
|
||||
while ((NodeRunner.CurrentPipeline != null) &&
|
||||
NodeRunner.CurrentPipeline.IsRunning &&
|
||||
!cts.Token.IsCancellationRequested &&
|
||||
NodeRunner.CurrentPipeline!.RequestNexConcurrentNode( out node ) )
|
||||
NodeRunner.CurrentPipeline!.RequestNexConcurrentNode(out node))
|
||||
{
|
||||
node.Run();
|
||||
if( !NodeRunner.CurrentPipeline!.IsRunning )
|
||||
if (!NodeRunner.CurrentPipeline!.IsRunning)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
( NodeRunner.CurrentPipeline!.EndLayer as EndingNode )!.Run();
|
||||
bool isEmpty = pipelineInWaiting.TryPop( out PipelineScheduler? pipeline );
|
||||
(NodeRunner.CurrentPipeline!.EndLayer as EndingNode)!.Run();
|
||||
bool isEmpty = pipelineInWaiting.TryPop(out PipelineScheduler? pipeline);
|
||||
NodeRunner.CurrentPipeline = pipeline!;
|
||||
return isEmpty;
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
if( ( NodeRunner.CurrentPipeline == null ) || //no bp running at all
|
||||
( ( pipelineInWaiting.IsEmpty ) && ( NodeRunner.CurrentPipeline.IsRunning == false ) ) )
|
||||
if ((NodeRunner.CurrentPipeline == null) || //no bp running at all
|
||||
((pipelineInWaiting.IsEmpty) && (NodeRunner.CurrentPipeline.IsRunning == false)))
|
||||
{
|
||||
// a bp is quitting
|
||||
//in case no bp is running
|
||||
// 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 )
|
||||
foreach (NodeRunner item in allAvailableTask)
|
||||
{
|
||||
if( item.Id == id )
|
||||
if (item.Id == id)
|
||||
{
|
||||
//if calling from any bp running task
|
||||
// if calling from any bp running task
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -227,18 +222,18 @@ namespace StgSharp.PipeLine
|
||||
{
|
||||
_startup = InternalRun
|
||||
};
|
||||
ret._internalTask = Task.Run( ret.InternalAction );
|
||||
ret._internalTask = Task.Run(ret.InternalAction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static void InternalRun( CancellationToken token )
|
||||
private static void InternalRun(CancellationToken token)
|
||||
{
|
||||
PipelineNode item;
|
||||
Console.WriteLine( $"Global thread {Environment.CurrentManagedThreadId} starts." );
|
||||
while( ( CurrentPipeline != null ) &&
|
||||
Console.WriteLine($"Global thread {Environment.CurrentManagedThreadId} starts.");
|
||||
while ((CurrentPipeline != null) &&
|
||||
CurrentPipeline.IsRunning &&
|
||||
!token.IsCancellationRequested &&
|
||||
CurrentPipeline.RequestNexConcurrentNode( out item ) ) {
|
||||
CurrentPipeline.RequestNexConcurrentNode(out item)) {
|
||||
item.Run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PipelineMarshal.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipelineMarshal"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
@@ -41,11 +38,10 @@ namespace StgSharp.PipeLine
|
||||
public static class PipelineMarshal
|
||||
{
|
||||
|
||||
public static IEnumerable<PipelineNode> GetNodeSortedEnumeration(
|
||||
PipelineScheduler scheduler )
|
||||
public static IEnumerable<PipelineNode> GetNodeSortedEnumeration(PipelineScheduler scheduler)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( scheduler );
|
||||
return new PipelineNodeEnumerator( scheduler )
|
||||
ArgumentNullException.ThrowIfNull(scheduler);
|
||||
return new PipelineNodeEnumerator(scheduler)
|
||||
{
|
||||
_count = scheduler._allNode.Count,
|
||||
};
|
||||
@@ -58,10 +54,10 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public int _count;
|
||||
|
||||
public PipelineNodeEnumerator( PipelineScheduler scheduler )
|
||||
public PipelineNodeEnumerator(PipelineScheduler scheduler)
|
||||
{
|
||||
if( !scheduler.TryGetAllNode( out _mt, out _c ) ) {
|
||||
throw new InvalidOperationException( "Binded scheduler is not sorted." );
|
||||
if (!scheduler.TryGetAllNode(out _mt, out _c)) {
|
||||
throw new InvalidOperationException("Binded scheduler is not sorted.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +67,18 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public IEnumerator<PipelineNode> GetEnumerator()
|
||||
{
|
||||
for( int i = 1; i < _mt.Count; i++ )
|
||||
for (int i = 1; i < _mt.Count; i++)
|
||||
{
|
||||
foreach( PipelineNode node in _mt[ i ] ) {
|
||||
foreach (PipelineNode node in _mt[i]) {
|
||||
yield return node;
|
||||
}
|
||||
foreach( PipelineNode node in _c[ i ] ) {
|
||||
foreach (PipelineNode node in _c[i]) {
|
||||
yield return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<PipelineNode>.Add( PipelineNode item )
|
||||
void ICollection<PipelineNode>.Add(PipelineNode item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
@@ -92,17 +88,17 @@ namespace StgSharp.PipeLine
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
bool ICollection<PipelineNode>.Contains( PipelineNode item )
|
||||
bool ICollection<PipelineNode>.Contains(PipelineNode item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICollection<PipelineNode>.CopyTo( PipelineNode[] array, int arrayIndex )
|
||||
void ICollection<PipelineNode>.CopyTo(PipelineNode[] array, int arrayIndex)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
bool ICollection<PipelineNode>.Remove( PipelineNode item )
|
||||
bool ICollection<PipelineNode>.Remove(PipelineNode item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipelineNode.cs"
|
||||
// file="PipelineNode"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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.
|
||||
// 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.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PipelineNodeLabel.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipelineNodeLabel"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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.Diagnostics.CodeAnalysis;
|
||||
@@ -40,6 +37,7 @@ namespace StgSharp.PipeLine
|
||||
{
|
||||
public abstract record class PipelineNodeLabel
|
||||
{
|
||||
|
||||
public static PipelineNodeLabel Empty => PipelineNodeLabelEmpty.Only;
|
||||
|
||||
public abstract int ComputeHashCode();
|
||||
@@ -48,11 +46,13 @@ namespace StgSharp.PipeLine
|
||||
{
|
||||
return ComputeHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public record class PipelineNodeStringLabel : PipelineNodeLabel
|
||||
{
|
||||
public PipelineNodeStringLabel( string name )
|
||||
|
||||
public PipelineNodeStringLabel(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
@@ -61,17 +61,20 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public override int ComputeHashCode()
|
||||
{
|
||||
return string.GetHashCode( Name );
|
||||
return string.GetHashCode(Name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal record class PipelineNodeLabelEmpty : PipelineNodeLabel
|
||||
{
|
||||
|
||||
public static PipelineNodeLabelEmpty Only { get; } = new PipelineNodeLabelEmpty();
|
||||
|
||||
public override int ComputeHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PipelineNodePort.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipelineNodePort"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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;
|
||||
@@ -43,7 +40,7 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private HashSet<PipelineNodeOutPort> _linkerSet = new HashSet<PipelineNodeOutPort>();
|
||||
|
||||
public PipelineNodeInPort( PipelineNode container, string label )
|
||||
public PipelineNodeInPort(PipelineNode container, string label)
|
||||
{
|
||||
Container = container;
|
||||
Label = label;
|
||||
@@ -59,45 +56,45 @@ namespace StgSharp.PipeLine
|
||||
|
||||
internal HashSet<PipelineNodeOutPort> Linkers => _linkerSet;
|
||||
|
||||
public void Connect( PipelineNodeOutPort port )
|
||||
public void Connect(PipelineNodeOutPort port)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( port );
|
||||
if( _linkerSet.Add( port ) )
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
if (_linkerSet.Add(port))
|
||||
{
|
||||
port.Linkers.Add( this );
|
||||
Container.Previous.Add( port.Container );
|
||||
port.Container.Next.Add( Container );
|
||||
port.Linkers.Add(this);
|
||||
Container.Previous.Add(port.Container);
|
||||
port.Container.Next.Add(Container);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<PipelineNode> GetFormerNodes()
|
||||
{
|
||||
foreach( PipelineNodeOutPort port in _linkerSet ) {
|
||||
foreach (PipelineNodeOutPort port in _linkerSet) {
|
||||
yield return port.Container;
|
||||
}
|
||||
}
|
||||
|
||||
public void Wait()
|
||||
{
|
||||
PipelineNodeOutPort.WaitAll( _linkerSet );
|
||||
PipelineNodeOutPort.WaitAll(_linkerSet);
|
||||
}
|
||||
|
||||
public static void WaitAll( IDictionary<string, PipelineNodeInPort> ports )
|
||||
public static void WaitAll(IDictionary<string, PipelineNodeInPort> ports)
|
||||
{
|
||||
if( ports is null ) {
|
||||
if (ports is null) {
|
||||
return;
|
||||
}
|
||||
foreach( PipelineNodeInPort port in ports.Values ) {
|
||||
foreach (PipelineNodeInPort port in ports.Values) {
|
||||
port.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public static void WaitAll( IEnumerable<PipelineNodeInPort> ports )
|
||||
public static void WaitAll(IEnumerable<PipelineNodeInPort> ports)
|
||||
{
|
||||
if( ports is null ) {
|
||||
if (ports is null) {
|
||||
return;
|
||||
}
|
||||
foreach( PipelineNodeInPort port in ports ) {
|
||||
foreach (PipelineNodeInPort port in ports) {
|
||||
port.Wait();
|
||||
}
|
||||
}
|
||||
@@ -111,11 +108,11 @@ namespace StgSharp.PipeLine
|
||||
private volatile int _passCount;
|
||||
private SemaphoreSlim formerCompleteSemaphore;
|
||||
|
||||
public PipelineNodeOutPort( PipelineNode container, string label )
|
||||
public PipelineNodeOutPort(PipelineNode container, string label)
|
||||
{
|
||||
Container = container;
|
||||
Label = label;
|
||||
formerCompleteSemaphore = new SemaphoreSlim( initialCount: 0, maxCount: 1 );
|
||||
formerCompleteSemaphore = new SemaphoreSlim(initialCount:0, maxCount:1);
|
||||
}
|
||||
|
||||
public PipelineNode Container { get; init; }
|
||||
@@ -126,20 +123,20 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private SemaphoreSlim Waiter => formerCompleteSemaphore;
|
||||
|
||||
public void Connect( PipelineNodeInPort port )
|
||||
public void Connect(PipelineNodeInPort port)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( port );
|
||||
if( _linkerSet.Add( port ) )
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
if (_linkerSet.Add(port))
|
||||
{
|
||||
port.Linkers.Add( this );
|
||||
Container.Next.Add( port.Container );
|
||||
port.Container.Previous.Add( Container );
|
||||
port.Linkers.Add(this);
|
||||
Container.Next.Add(port.Container);
|
||||
port.Container.Previous.Add(Container);
|
||||
}
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
if( _passCount == 0 )
|
||||
if (_passCount == 0)
|
||||
{
|
||||
Waiter.Release();
|
||||
} else
|
||||
@@ -148,27 +145,27 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
}
|
||||
|
||||
public static void SkipAll( Dictionary<string, PipelineNodeOutPort> ports )
|
||||
public static void SkipAll(Dictionary<string, PipelineNodeOutPort> ports)
|
||||
{
|
||||
if( ports is null ) {
|
||||
if (ports is null) {
|
||||
return;
|
||||
}
|
||||
foreach( PipelineNodeOutPort port in ports.Values ) {
|
||||
foreach (PipelineNodeOutPort port in ports.Values) {
|
||||
port.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public void TransmitValue( IPipeLineConnectionPayload value )
|
||||
public void TransmitValue(IPipeLineConnectionPayload value)
|
||||
{
|
||||
foreach( PipelineNodeInPort item in _linkerSet ) { }
|
||||
foreach (PipelineNodeInPort item in _linkerSet) { }
|
||||
}
|
||||
|
||||
public static void WaitAll( IEnumerable<PipelineNodeOutPort> ports )
|
||||
public static void WaitAll(IEnumerable<PipelineNodeOutPort> ports)
|
||||
{
|
||||
if( ports is null ) {
|
||||
if (ports is null) {
|
||||
return;
|
||||
}
|
||||
foreach( PipelineNodeOutPort port in ports ) {
|
||||
foreach (PipelineNodeOutPort port in ports) {
|
||||
port.Wait();
|
||||
}
|
||||
}
|
||||
@@ -176,12 +173,12 @@ namespace StgSharp.PipeLine
|
||||
internal void Wait()
|
||||
{
|
||||
Waiter.Wait();
|
||||
if( _passCount >= _linkerSet.Count )
|
||||
if (_passCount >= _linkerSet.Count)
|
||||
{
|
||||
Interlocked.Exchange( ref _passCount, 0 );
|
||||
Interlocked.Exchange(ref _passCount, 0);
|
||||
} else
|
||||
{
|
||||
Interlocked.Increment( ref _passCount );
|
||||
Interlocked.Increment(ref _passCount);
|
||||
Waiter.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PipelineScheduler.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PipelineScheduler"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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;
|
||||
@@ -54,21 +51,21 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private int mtLevel, cLevel,mtIndex, cIndex;
|
||||
private List<List<PipelineNode>> _concurrentNodes, _mainThreadNodes ;
|
||||
private SemaphoreSlim runningStat,_concurrentLock = new SemaphoreSlim( 1, 1 );
|
||||
private SemaphoreSlim runningStat,_concurrentLock = new SemaphoreSlim(1, 1);
|
||||
internal Dictionary<PipelineNodeLabel, PipelineNode> _allNode;
|
||||
|
||||
public PipelineScheduler()
|
||||
{
|
||||
_allNode = new Dictionary<PipelineNodeLabel, PipelineNode>();
|
||||
runningStat = new SemaphoreSlim( 1, 1 );
|
||||
_beginning = new BeginningNode( this );
|
||||
_ending = new EndingNode( this );
|
||||
runningStat = new SemaphoreSlim(1, 1);
|
||||
_beginning = new BeginningNode(this);
|
||||
_ending = new EndingNode(this);
|
||||
}
|
||||
/**/
|
||||
|
||||
public PipelineNode this[ PipelineNodeLabel label ]
|
||||
public PipelineNode this[PipelineNodeLabel label]
|
||||
{
|
||||
get { return _allNode[ label ]; }
|
||||
get { return _allNode[label]; }
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
@@ -92,7 +89,7 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public PipelineNodeOperation Operation
|
||||
{
|
||||
get => ( this as IConvertableToPipelineNode ).NodeMain;
|
||||
get => (this as IConvertableToPipelineNode).NodeMain;
|
||||
}
|
||||
|
||||
/**/
|
||||
@@ -102,85 +99,83 @@ namespace StgSharp.PipeLine
|
||||
get => runningStat;
|
||||
}
|
||||
|
||||
public void AddNode( PipelineNode node, bool isNative )
|
||||
public void AddNode(PipelineNode node, bool isNative)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( node );
|
||||
ArgumentNullException.ThrowIfNull(node);
|
||||
node.IsNative = isNative;
|
||||
_allNode.TryAdd( node.Label, node );
|
||||
_allNode.TryAdd(node.Label, node);
|
||||
}
|
||||
|
||||
public void ArrangeNodes()
|
||||
{
|
||||
if( _isAvailable ) {
|
||||
if (_isAvailable) {
|
||||
return;
|
||||
}
|
||||
int maxLevel = 1;
|
||||
Queue<PipelineNode> completedNodes = new Queue<PipelineNode>();
|
||||
foreach( PipelineNode item in _beginning.Next )
|
||||
foreach (PipelineNode item in _beginning.Next)
|
||||
{
|
||||
item.TryIncreaseLevelTo( 1 );
|
||||
completedNodes.Enqueue( item );
|
||||
item.TryIncreaseLevelTo(1);
|
||||
completedNodes.Enqueue(item);
|
||||
}
|
||||
|
||||
//calc level of nodes O(V)
|
||||
while( completedNodes.Count > 0 )
|
||||
// calc level of nodes O(V)
|
||||
while (completedNodes.Count > 0)
|
||||
{
|
||||
PipelineNode u = completedNodes.Dequeue();
|
||||
foreach( PipelineNode v in u.Next )
|
||||
foreach (PipelineNode v in u.Next)
|
||||
{
|
||||
if( !v.TryIncreaseLevelTo( u.Level + 1 ) ) {
|
||||
throw new InvalidOperationException( "Ring in DAG detected." );
|
||||
if (!v.TryIncreaseLevelTo(u.Level + 1)) {
|
||||
throw new InvalidOperationException("Ring in DAG detected.");
|
||||
}
|
||||
if( v.RemainingIncreaseCount == 0 )
|
||||
if (v.RemainingIncreaseCount == 0)
|
||||
{
|
||||
completedNodes.Enqueue( v );
|
||||
maxLevel = int.Max( maxLevel, v.Level );
|
||||
completedNodes.Enqueue(v);
|
||||
maxLevel = int.Max(maxLevel, v.Level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//bucket sort of nodes, O(E)
|
||||
_concurrentNodes = new List<List<PipelineNode>>( maxLevel + 1 );
|
||||
_mainThreadNodes = new List<List<PipelineNode>>( maxLevel + 1 );
|
||||
for( int i = 0; i <= maxLevel; i++ )
|
||||
// bucket sort of nodes, O(E)
|
||||
_concurrentNodes = new List<List<PipelineNode>>(maxLevel + 1);
|
||||
_mainThreadNodes = new List<List<PipelineNode>>(maxLevel + 1);
|
||||
for (int i = 0; i <= maxLevel; i++)
|
||||
{
|
||||
_concurrentNodes.Add( [] );
|
||||
_mainThreadNodes.Add( [] );
|
||||
_concurrentNodes.Add([]);
|
||||
_mainThreadNodes.Add([]);
|
||||
}
|
||||
foreach( PipelineNode item in _allNode.Values )
|
||||
foreach (PipelineNode item in _allNode.Values)
|
||||
{
|
||||
if( item.IsNative )
|
||||
if (item.IsNative)
|
||||
{
|
||||
_mainThreadNodes[ item.Level ].Add( item );
|
||||
_mainThreadNodes[item.Level].Add(item);
|
||||
} else
|
||||
{
|
||||
_concurrentNodes[ item.Level ].Add( item );
|
||||
_concurrentNodes[item.Level].Add(item);
|
||||
}
|
||||
}
|
||||
foreach( List<PipelineNode> item in _concurrentNodes ) {
|
||||
foreach (List<PipelineNode> item in _concurrentNodes) {
|
||||
item.TrimExcess();
|
||||
}
|
||||
foreach( List<PipelineNode> item in _mainThreadNodes ) {
|
||||
foreach (List<PipelineNode> item in _mainThreadNodes) {
|
||||
item.TrimExcess();
|
||||
}
|
||||
_isAvailable = true;
|
||||
}
|
||||
|
||||
public PipelineNode Create(
|
||||
PipelineNodeLabel label,
|
||||
[NotNull] IConvertableToPipelineNode body )
|
||||
public PipelineNode Create(PipelineNodeLabel label, [NotNull] IConvertableToPipelineNode body)
|
||||
{
|
||||
if( _allNode.TryGetValue( label, out PipelineNode? node ) ) {
|
||||
throw new InvalidOperationException( "Label has exist in scheduler." );
|
||||
if (_allNode.TryGetValue(label, out PipelineNode? node)) {
|
||||
throw new InvalidOperationException("Label has exist in scheduler.");
|
||||
}
|
||||
node = new PipelineNode( label, body, false );
|
||||
_allNode.Add( label, node );
|
||||
node = new PipelineNode(label, body, false);
|
||||
_allNode.Add(label, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
public PipelineNode GetNode( PipelineNodeLabel label )
|
||||
public PipelineNode GetNode(PipelineNodeLabel label)
|
||||
{
|
||||
if( _allNode.TryGetValue( label, out PipelineNode? node ) )
|
||||
if (_allNode.TryGetValue(label, out PipelineNode? node))
|
||||
{
|
||||
return node;
|
||||
} else
|
||||
@@ -189,24 +184,24 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
}
|
||||
|
||||
public void LinkToInput( PipelineNodeInPort port )
|
||||
public void LinkToInput(PipelineNodeInPort port)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( port );
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
PipelineNodeOutPort p = _beginning.DefaultOut;
|
||||
p.Connect( port );
|
||||
p.Connect(port);
|
||||
}
|
||||
|
||||
public void LinkToInput( PipelineNodeInPort port, string inputPortName )
|
||||
public void LinkToInput(PipelineNodeInPort port, string inputPortName)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( port );
|
||||
PipelineNodeOutPort p = _beginning.DefineCertainOutputPort( inputPortName );
|
||||
p.Connect( port );
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
PipelineNodeOutPort p = _beginning.DefineCertainOutputPort(inputPortName);
|
||||
p.Connect(port);
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetInput( params (string label, IPipeLineConnectionPayload arg)[] parameters )
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetInput(params (string label, IPipeLineConnectionPayload arg)[] parameters)
|
||||
{
|
||||
_beginning.SetInputData( parameters );
|
||||
_beginning.SetInputData(parameters);
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
@@ -218,9 +213,9 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public bool TryGetAllNode(
|
||||
out List<List<PipelineNode>> mainThreadNodes,
|
||||
out List<List<PipelineNode>> concurrentNodes )
|
||||
out List<List<PipelineNode>> concurrentNodes)
|
||||
{
|
||||
if( _isAvailable )
|
||||
if (_isAvailable)
|
||||
{
|
||||
mainThreadNodes = _mainThreadNodes;
|
||||
concurrentNodes = _concurrentNodes;
|
||||
@@ -231,20 +226,20 @@ namespace StgSharp.PipeLine
|
||||
return false;
|
||||
}
|
||||
|
||||
internal bool RequestNexConcurrentNode( out PipelineNode node )
|
||||
internal bool RequestNexConcurrentNode(out PipelineNode node)
|
||||
{
|
||||
int index, level;
|
||||
if( cLevel >= _concurrentNodes.Count )
|
||||
if (cLevel >= _concurrentNodes.Count)
|
||||
{
|
||||
node = null!;
|
||||
return false;
|
||||
}
|
||||
_concurrentLock.Wait();
|
||||
while( cIndex >= _concurrentNodes[ cLevel ].Count )
|
||||
while (cIndex >= _concurrentNodes[cLevel].Count)
|
||||
{
|
||||
Interlocked.Increment( ref cLevel );
|
||||
Interlocked.Exchange( ref cIndex, 0 );
|
||||
if( cLevel >= _concurrentNodes.Count )
|
||||
Interlocked.Increment(ref cLevel);
|
||||
Interlocked.Exchange(ref cIndex, 0);
|
||||
if (cLevel >= _concurrentNodes.Count)
|
||||
{
|
||||
node = null!;
|
||||
return false;
|
||||
@@ -252,30 +247,30 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
index = cIndex;
|
||||
level = cLevel;
|
||||
Interlocked.Increment( ref cIndex );
|
||||
Interlocked.Increment(ref cIndex);
|
||||
_concurrentLock.Release();
|
||||
node = _concurrentNodes[ level ][ index ];
|
||||
node = _concurrentNodes[level][index];
|
||||
return true;
|
||||
}
|
||||
|
||||
internal bool RequestNextMainThreadNode( out PipelineNode node )
|
||||
internal bool RequestNextMainThreadNode(out PipelineNode node)
|
||||
{
|
||||
if( mtLevel >= _mainThreadNodes.Count )
|
||||
if (mtLevel >= _mainThreadNodes.Count)
|
||||
{
|
||||
node = null!;
|
||||
return false;
|
||||
}
|
||||
while( mtIndex >= _mainThreadNodes[ cLevel ].Count )
|
||||
while (mtIndex >= _mainThreadNodes[cLevel].Count)
|
||||
{
|
||||
Interlocked.Increment( ref mtLevel );
|
||||
Interlocked.Exchange( ref mtIndex, 0 );
|
||||
if( mtLevel >= _mainThreadNodes.Count )
|
||||
Interlocked.Increment(ref mtLevel);
|
||||
Interlocked.Exchange(ref mtIndex, 0);
|
||||
if (mtLevel >= _mainThreadNodes.Count)
|
||||
{
|
||||
node = null!;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
node = _mainThreadNodes[ mtLevel ][ mtIndex ];
|
||||
node = _mainThreadNodes[mtLevel][mtIndex];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -287,10 +282,10 @@ namespace StgSharp.PipeLine
|
||||
|
||||
void IConvertableToPipelineNode.NodeMain(
|
||||
in Dictionary<string, PipelineNodeInPort> input,
|
||||
in Dictionary<string, PipelineNodeOutPort> output )
|
||||
in Dictionary<string, PipelineNodeOutPort> output)
|
||||
{
|
||||
PipeLineRunner.Run( this );
|
||||
PipelineNodeOutPort.SkipAll( output );
|
||||
PipeLineRunner.Run(this);
|
||||
PipelineNodeOutPort.SkipAll(output);
|
||||
}
|
||||
|
||||
~PipelineScheduler()
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PortArgs.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PortArgs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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;
|
||||
@@ -48,11 +45,11 @@ namespace StgSharp.PipeLine
|
||||
private protected PipelineNodeOutPort input;
|
||||
private protected SemaphoreSlim formerCompleteSemaphore;
|
||||
|
||||
public PipelineConnector( PipelineNodeOutPort former, PipelineNodeInPort after )
|
||||
public PipelineConnector(PipelineNodeOutPort former, PipelineNodeInPort after)
|
||||
{
|
||||
this.input = former;
|
||||
this.output = after;
|
||||
formerCompleteSemaphore = new SemaphoreSlim( initialCount: 0, maxCount: 1 );
|
||||
formerCompleteSemaphore = new SemaphoreSlim(initialCount:0, maxCount:1);
|
||||
}
|
||||
|
||||
public IPipeLineConnectionPayload Args
|
||||
@@ -65,36 +62,36 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public PipelineNodeOutPort Input => input;
|
||||
|
||||
public static void SkipAll( Dictionary<string, PipelineConnector> ports )
|
||||
public static void SkipAll(Dictionary<string, PipelineConnector> ports)
|
||||
{
|
||||
if( ports == null ) {
|
||||
if (ports == null) {
|
||||
return;
|
||||
}
|
||||
foreach( KeyValuePair<string, PipelineConnector> item in ports )
|
||||
foreach (KeyValuePair<string, PipelineConnector> item in ports)
|
||||
{
|
||||
if( item.Value != null ) {
|
||||
if (item.Value != null) {
|
||||
item.Value.CompleteAndSkip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void WaitAll( Dictionary<string, PipelineConnector> ports )
|
||||
public static void WaitAll(Dictionary<string, PipelineConnector> ports)
|
||||
{
|
||||
if( ports == null ) {
|
||||
if (ports == null) {
|
||||
return;
|
||||
}
|
||||
foreach( KeyValuePair<string, PipelineConnector> item in ports )
|
||||
foreach (KeyValuePair<string, PipelineConnector> item in ports)
|
||||
{
|
||||
if( item.Value != null ) {
|
||||
if (item.Value != null) {
|
||||
item.Value.WaitForStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public virtual void WaitForStart()
|
||||
{
|
||||
//Console.WriteLine($"Waiting \t{input.ContextName}\t->\t{output.ContextName}");
|
||||
// Console.WriteLine($"Waiting \t{input.ContextName}\t->\t{output.ContextName}");
|
||||
formerCompleteSemaphore.Wait();
|
||||
}
|
||||
|
||||
@@ -105,15 +102,15 @@ namespace StgSharp.PipeLine
|
||||
|
||||
#region pipline op
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CompleteAndSkip()
|
||||
{
|
||||
//Console.WriteLine($"Complete\t{input.Name}\t->\t{output.Name}");
|
||||
// Console.WriteLine($"Complete\t{input.Name}\t->\t{output.Name}");
|
||||
formerCompleteSemaphore.Release();
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void CompleteAndWriteData( IPipeLineConnectionPayload args )
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CompleteAndWriteData(IPipeLineConnectionPayload args)
|
||||
{
|
||||
this.args = args;
|
||||
CompleteAndSkip();
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="SideNode.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SideNode"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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:
|
||||
// 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.
|
||||
//
|
||||
// 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.Globalization;
|
||||
@@ -46,29 +43,28 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private PipelineScheduler _bp;
|
||||
|
||||
public BeginningNode( PipelineScheduler bp )
|
||||
public BeginningNode(PipelineScheduler bp)
|
||||
: base(
|
||||
DefaultOperation, new PipelineNodeStringLabel( "BeginningNode" ), true, ["default"],
|
||||
[OutName] )
|
||||
DefaultOperation, new PipelineNodeStringLabel("BeginningNode"), true, [ "default" ],[ OutName ])
|
||||
{
|
||||
_bp = bp;
|
||||
}
|
||||
|
||||
public PipelineNodeOutPort DefaultOut => OutputPorts[ OutName ];
|
||||
public PipelineNodeOutPort DefaultOut => OutputPorts[OutName];
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
_bp.RunningStat.Wait();
|
||||
PipelineNodeOutPort.SkipAll( _output );
|
||||
PipelineNodeOutPort.SkipAll(_output);
|
||||
}
|
||||
|
||||
internal void SetInputData( IEnumerable<(string, IPipeLineConnectionPayload)> data )
|
||||
internal void SetInputData(IEnumerable<(string, IPipeLineConnectionPayload)> data)
|
||||
{
|
||||
if( data is null ) {
|
||||
if (data is null) {
|
||||
return;
|
||||
}
|
||||
foreach( (string, IPipeLineConnectionPayload) item in data ) {
|
||||
OutputPorts[ item.Item1 ].TransmitValue( item.Item2 );
|
||||
foreach ((string, IPipeLineConnectionPayload) item in data) {
|
||||
OutputPorts[item.Item1].TransmitValue(item.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,17 +75,16 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private PipelineScheduler _bp;
|
||||
|
||||
public EndingNode( PipelineScheduler bp )
|
||||
public EndingNode(PipelineScheduler bp)
|
||||
: base(
|
||||
DefaultOperation, name: new PipelineNodeStringLabel( "EndingNode" ), true, ["default"],
|
||||
["default"] )
|
||||
DefaultOperation, name:new PipelineNodeStringLabel("EndingNode"), true, [ "default" ],[ "default" ])
|
||||
{
|
||||
_bp = bp;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
PipelineNodeInPort.WaitAll( _input );
|
||||
PipelineNodeInPort.WaitAll(_input);
|
||||
_bp.ResetIndex();
|
||||
_bp.RunningStat.Release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user