Daily update on 20250423-143640 by Nitload Youmu. Additional Message : none
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -38,7 +38,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.PipeLine
|
||||
{
|
||||
public class CrossFrameOperation : IConvertableToBlueprintNode
|
||||
public class CrossFrameOperation : IConvertableToPipelineNode
|
||||
{
|
||||
|
||||
private static string[] _inputName = ["TaskIn"];
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IConvertableToPipelineNode.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.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.PipeLine
|
||||
{
|
||||
public delegate void PipelineNodeOperation(
|
||||
in Dictionary<string, PipelineNodeImport> input,
|
||||
in Dictionary<string, PipelineNodeExport> output );
|
||||
|
||||
public interface IConvertableToPipelineNode
|
||||
{
|
||||
|
||||
public IEnumerable<string> InputInterfacesName { get; }
|
||||
|
||||
public IEnumerable<string> OutputInterfacesName { get; }
|
||||
|
||||
PipelineNodeOperation Operation { get; }
|
||||
|
||||
void NodeMain(
|
||||
in Dictionary<string, PipelineNodeImport> input,
|
||||
in Dictionary<string, PipelineNodeExport> output );
|
||||
|
||||
}
|
||||
|
||||
internal class DefaultConvertableToBlueprintNode : IConvertableToPipelineNode
|
||||
{
|
||||
|
||||
private string[] _input;
|
||||
private string[] _output;
|
||||
private PipelineNodeOperation _execution;
|
||||
|
||||
public DefaultConvertableToBlueprintNode(
|
||||
PipelineNodeOperation execution,
|
||||
string[] input,
|
||||
string[] output )
|
||||
{
|
||||
_input = input;
|
||||
_output = output;
|
||||
_execution = execution;
|
||||
}
|
||||
|
||||
public IEnumerable<string> InputInterfacesName => _input;
|
||||
|
||||
public IEnumerable<string> OutputInterfacesName => _output;
|
||||
|
||||
public PipelineNodeOperation Operation => _execution;
|
||||
|
||||
public void NodeMain(
|
||||
in Dictionary<string, PipelineNodeImport> input,
|
||||
in Dictionary<string, PipelineNodeExport> output )
|
||||
{
|
||||
_execution.Invoke( input, output );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,23 +48,23 @@ namespace StgSharp.PipeLine
|
||||
|
||||
private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray();
|
||||
private static CancellationTokenSource cts = new CancellationTokenSource();
|
||||
private static ConcurrentStack<PipelineScheduler> blueprintInWaiting
|
||||
private static ConcurrentStack<PipelineScheduler> pipelineInWaiting
|
||||
= 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
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( NodeRunner.CurrentBlueprint == null ) || //no bp running at all
|
||||
( ( blueprintInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning ==
|
||||
false ) ) )
|
||||
( ( pipelineInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning ==
|
||||
false ) ) )
|
||||
{
|
||||
// a bp is quitting
|
||||
//in case no bp is running
|
||||
@@ -104,7 +104,6 @@ namespace StgSharp.PipeLine
|
||||
if( InterruptAndRunNewBp( blueprint ) )
|
||||
{
|
||||
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
|
||||
;
|
||||
}
|
||||
} else
|
||||
{
|
||||
@@ -113,7 +112,6 @@ namespace StgSharp.PipeLine
|
||||
{
|
||||
while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { }
|
||||
}
|
||||
|
||||
bpLock.Release();
|
||||
}
|
||||
Interlocked.Exchange( ref _callingThread, -1 );
|
||||
@@ -143,19 +141,19 @@ namespace StgSharp.PipeLine
|
||||
foreach( NodeRunner task in allAvailableTask ) {
|
||||
task.Cts.Cancel();
|
||||
}
|
||||
foreach( PipelineScheduler bp in blueprintInWaiting ) {
|
||||
foreach( PipelineScheduler bp in pipelineInWaiting ) {
|
||||
bp.Terminate();
|
||||
}
|
||||
blueprintInWaiting.Clear();
|
||||
pipelineInWaiting.Clear();
|
||||
}
|
||||
|
||||
internal static bool InterruptAndRunNewBp( PipelineScheduler newBp )
|
||||
{
|
||||
Debug.Assert( newBp != null );
|
||||
ArgumentNullException.ThrowIfNull( newBp );
|
||||
if( ( newBp != NodeRunner.CurrentBlueprint ) && ( NodeRunner.CurrentBlueprint != null ) )
|
||||
{
|
||||
//if a running bp exists
|
||||
blueprintInWaiting.Push( NodeRunner.CurrentBlueprint );
|
||||
pipelineInWaiting.Push( NodeRunner.CurrentBlueprint );
|
||||
}
|
||||
|
||||
//load new bp to current bp
|
||||
@@ -188,7 +186,7 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
}
|
||||
( NodeRunner.CurrentBlueprint.EndLayer as EndingNode )!.Run();
|
||||
return blueprintInWaiting.TryPeek( out NodeRunner.CurrentBlueprint );
|
||||
return pipelineInWaiting.TryPeek( out NodeRunner.CurrentBlueprint );
|
||||
}
|
||||
|
||||
private static NodeRunner[] CreateBlueprintRunnerArray()
|
||||
|
||||
@@ -32,6 +32,7 @@ using StgSharp.Stg;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
@@ -44,7 +45,7 @@ namespace StgSharp.PipeLine
|
||||
/// 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
|
||||
public partial class PipelineScheduler : IConvertableToPipelineNode
|
||||
{
|
||||
|
||||
private BeginningNode _beginning;
|
||||
@@ -94,7 +95,7 @@ namespace StgSharp.PipeLine
|
||||
|
||||
public PipelineNodeOperation Operation
|
||||
{
|
||||
get => ( this as IConvertableToBlueprintNode ).NodeMain;
|
||||
get => ( this as IConvertableToPipelineNode ).NodeMain;
|
||||
}
|
||||
|
||||
/**/
|
||||
@@ -161,20 +162,10 @@ namespace StgSharp.PipeLine
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public PipelineNode Create( [NotNull]IConvertableToPipelineNode body, string name )
|
||||
{
|
||||
foreach( KeyValuePair<string, PipelineNode> item in allNode )
|
||||
{
|
||||
if( item.Value.IsNative )
|
||||
{
|
||||
mainThreadNodeList.Add( item.Value );
|
||||
} else
|
||||
{
|
||||
globalNodeList.Add( item.Value );
|
||||
}
|
||||
}
|
||||
mainThreadNodeList.Sort();
|
||||
globalNodeList.Sort();
|
||||
PipelineNode node = new PipelineNode( name, body, false );
|
||||
return node;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -213,9 +204,9 @@ namespace StgSharp.PipeLine
|
||||
return false;
|
||||
}
|
||||
|
||||
void IConvertableToBlueprintNode.NodeMain(
|
||||
in Dictionary<string, PipelineNodeImport> input,
|
||||
in Dictionary<string, PipelineNodeExport> output )
|
||||
void IConvertableToPipelineNode.NodeMain(
|
||||
in Dictionary<string, PipelineNodeImport> input,
|
||||
in Dictionary<string, PipelineNodeExport> output )
|
||||
{
|
||||
PipeLineRunner.Run( this );
|
||||
PipelineNodeExport.SkipAll( output );
|
||||
|
||||
Reference in New Issue
Block a user