add a scanner, but this seems to be a wrong solution. Change open-source head

This commit is contained in:
Youmu Liu
2026-07-07 18:20:38 +08:00
parent b053567eb7
commit 1705d7c245
276 changed files with 3468 additions and 7205 deletions
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.PipeLine;
using System;
@@ -38,13 +18,16 @@ 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) ?
@@ -65,14 +48,12 @@ namespace StgSharp.PipeLine
public IEnumerable<string> OutputPortName => _outputName;
public PipelineNodeOperation Operation
{
get => NodeMain;
}
public PipelineNodeOperation Operation => NodeMain;
public void NodeMain(
in Dictionary<string, PipelineNodeInPort> input,
in Dictionary<string, PipelineNodeOutPort> output)
in Dictionary<string, PipelineNodeOutPort> output
)
{
if (currentCount < cycleCount)
{
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -34,7 +14,8 @@ 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
{
@@ -47,7 +28,8 @@ namespace StgSharp.PipeLine
void NodeMain(
in Dictionary<string, PipelineNodeInPort> input,
in Dictionary<string, PipelineNodeOutPort> output);
in Dictionary<string, PipelineNodeOutPort> output
);
}
@@ -58,7 +40,11 @@ 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;
@@ -73,7 +59,8 @@ 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);
}
+22 -33
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Threading;
using System;
@@ -50,7 +30,9 @@ namespace StgSharp.PipeLine
private static int _callingThread;
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)
@@ -71,7 +53,9 @@ namespace StgSharp.PipeLine
Interlocked.Exchange(ref _callingThread, -1);
}
public static void SetMaxTaskCount(int size)
public static void SetMaxTaskCount(
int size
)
{
if (size < 1) {
size = 1;
@@ -104,7 +88,9 @@ namespace StgSharp.PipeLine
pipelineInWaiting.Clear();
}
internal static bool InterruptAndRunNewPipeline(PipelineScheduler newPipeline)
internal static bool InterruptAndRunNewPipeline(
PipelineScheduler newPipeline
)
{
ArgumentNullException.ThrowIfNull(newPipeline);
if ((newPipeline != NodeRunner.CurrentPipeline) && (NodeRunner.CurrentPipeline != null))
@@ -134,7 +120,8 @@ 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)
@@ -161,9 +148,9 @@ namespace StgSharp.PipeLine
}
/// <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()
{
@@ -226,7 +213,9 @@ namespace StgSharp.PipeLine
return ret;
}
private static void InternalRun(CancellationToken token)
private static void InternalRun(
CancellationToken token
)
{
PipelineNode item;
Console.WriteLine($"Global thread {Environment.CurrentManagedThreadId} starts.");
+24 -31
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
@@ -38,7 +18,9 @@ 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)
@@ -54,7 +36,9 @@ 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.");
@@ -78,7 +62,9 @@ namespace StgSharp.PipeLine
}
}
void ICollection<PipelineNode>.Add(PipelineNode item)
void ICollection<PipelineNode>.Add(
PipelineNode item
)
{
throw new NotSupportedException();
}
@@ -88,17 +74,24 @@ 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();
}
+47 -37
View File
@@ -1,30 +1,9 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// file="PipelineNode"
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
@@ -61,7 +40,11 @@ namespace StgSharp.PipeLine
private protected Dictionary<string, PipelineNodeOutPort> _output;
private protected int _level, _count;
internal PipelineNode(PipelineNodeLabel label, IConvertableToPipelineNode node, bool isNative)
internal PipelineNode(
PipelineNodeLabel label,
IConvertableToPipelineNode node,
bool isNative
)
{
_label = label;
_nativeRequested = isNative;
@@ -82,7 +65,8 @@ namespace StgSharp.PipeLine
PipelineNodeLabel name,
bool isNative,
string[] inputNames,
string[] outputNames)
string[] outputNames
)
#pragma warning restore CS8618
{
if ((inputNames == null) || (inputNames.Length == 0)) {
@@ -148,7 +132,12 @@ namespace StgSharp.PipeLine
internal int RemainingIncreaseCount => Previous.Count - _count;
public static void Connect(PipelineNode front, string frontNodePort, string backNodePort, PipelineNode back)
public static void Connect(
PipelineNode front,
string frontNodePort,
string backNodePort,
PipelineNode back
)
{
ArgumentNullException.ThrowIfNull(front);
ArgumentNullException.ThrowIfNull(back);
@@ -191,7 +180,9 @@ namespace StgSharp.PipeLine
}
}
internal bool TryIncreaseLevelTo(int level)
internal bool TryIncreaseLevelTo(
int level
)
{
_count++;
if (_count > Previous.Count) {
@@ -203,14 +194,17 @@ namespace StgSharp.PipeLine
protected static void DefaultOperation(
in Dictionary<string, PipelineNodeInPort> input,
in Dictionary<string, PipelineNodeOutPort> output)
in Dictionary<string, PipelineNodeOutPort> output
)
{
PipelineNodeOutPort.SkipAll(output);
}
#region port operation
public PipelineNodeInPort GetInputPort(string lable)
public PipelineNodeInPort GetInputPort(
string lable
)
{
if (!InputPorts.TryGetValue(lable, out PipelineNodeInPort? ret)) {
throw new ArgumentOutOfRangeException(
@@ -219,7 +213,9 @@ namespace StgSharp.PipeLine
return ret;
}
public PipelineNodeOutPort GetOutputPort(string lable)
public PipelineNodeOutPort GetOutputPort(
string lable
)
{
if (!OutputPorts.TryGetValue(lable, out PipelineNodeOutPort? ret)) {
throw new ArgumentOutOfRangeException(
@@ -228,7 +224,9 @@ namespace StgSharp.PipeLine
return ret;
}
public PipelineNodeInPort? DefineCertainInputPort(string label)
public PipelineNodeInPort? DefineCertainInputPort(
string label
)
{
if (InputPorts.ContainsKey(label)) {
return null;
@@ -238,7 +236,9 @@ namespace StgSharp.PipeLine
return port;
}
public PipelineNodeOutPort? DefineCertainOutputPort(string label)
public PipelineNodeOutPort? DefineCertainOutputPort(
string label
)
{
if (OutputPorts.ContainsKey(label)) {
return null;
@@ -256,11 +256,21 @@ namespace StgSharp.PipeLine
public PipelineNodeRunException() { }
public PipelineNodeRunException(Exception ex) : base(string.Empty, ex) { }
public PipelineNodeRunException(
Exception ex
)
: base(string.Empty, ex) { }
public PipelineNodeRunException(string message) : base(message) { }
public PipelineNodeRunException(
string message
)
: base(message) { }
public PipelineNodeRunException(string message, Exception innerException) : base(message, innerException) { }
public PipelineNodeRunException(
string message,
Exception innerException
)
: base(message, innerException) { }
}
}
+8 -26
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -52,7 +32,9 @@ namespace StgSharp.PipeLine
public record class PipelineNodeStringLabel : PipelineNodeLabel
{
public PipelineNodeStringLabel(string name)
public PipelineNodeStringLabel(
string name
)
{
Name = name;
}
+34 -34
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
@@ -40,7 +20,10 @@ 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;
@@ -56,7 +39,9 @@ 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))
@@ -79,7 +64,9 @@ namespace StgSharp.PipeLine
PipelineNodeOutPort.WaitAll(_linkerSet);
}
public static void WaitAll(IDictionary<string, PipelineNodeInPort> ports)
public static void WaitAll(
IDictionary<string, PipelineNodeInPort> ports
)
{
if (ports is null) {
return;
@@ -89,7 +76,9 @@ namespace StgSharp.PipeLine
}
}
public static void WaitAll(IEnumerable<PipelineNodeInPort> ports)
public static void WaitAll(
IEnumerable<PipelineNodeInPort> ports
)
{
if (ports is null) {
return;
@@ -108,7 +97,10 @@ 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;
@@ -123,7 +115,9 @@ namespace StgSharp.PipeLine
private SemaphoreSlim Waiter => formerCompleteSemaphore;
public void Connect(PipelineNodeInPort port)
public void Connect(
PipelineNodeInPort port
)
{
ArgumentNullException.ThrowIfNull(port);
if (_linkerSet.Add(port))
@@ -145,7 +139,9 @@ namespace StgSharp.PipeLine
}
}
public static void SkipAll(Dictionary<string, PipelineNodeOutPort> ports)
public static void SkipAll(
Dictionary<string, PipelineNodeOutPort> ports
)
{
if (ports is null) {
return;
@@ -155,12 +151,16 @@ namespace StgSharp.PipeLine
}
}
public void TransmitValue(IPipeLineConnectionPayload value)
public void TransmitValue(
IPipeLineConnectionPayload value
)
{
foreach (PipelineNodeInPort item in _linkerSet) { }
}
public static void WaitAll(IEnumerable<PipelineNodeOutPort> ports)
public static void WaitAll(
IEnumerable<PipelineNodeOutPort> ports
)
{
if (ports is null) {
return;
+44 -59
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// file="PipelineScheduler"
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -61,43 +41,30 @@ namespace StgSharp.PipeLine
}
/**/
public PipelineNode this[PipelineNodeLabel label]
{
get { return _allNode[label]; }
}
public PipelineNode this[
PipelineNodeLabel label
] => _allNode[label];
public bool IsRunning
{
get => runningStat.CurrentCount == 0;
}
public bool IsRunning => runningStat.CurrentCount == 0;
public IEnumerable<string> InputPortName
{
get => _beginning.InputPorts.Keys;
}
public IEnumerable<string> InputPortName => _beginning.InputPorts.Keys;
public IEnumerable<string> OutputPortName
{
get => _beginning.OutputPorts.Keys;
}
public IEnumerable<string> OutputPortName => _beginning.OutputPorts.Keys;
public PipelineNode BeginLayer => _beginning;
public PipelineNode EndLayer => _ending;
public PipelineNodeOperation Operation
{
get => (this as IConvertableToPipelineNode).NodeMain;
}
public PipelineNodeOperation Operation => (this as IConvertableToPipelineNode).NodeMain;
/**/
internal SemaphoreSlim RunningStat
{
get => runningStat;
}
internal SemaphoreSlim RunningStat => runningStat;
public void AddNode(PipelineNode node, bool isNative)
public void AddNode(
PipelineNode node,
bool isNative
)
{
ArgumentNullException.ThrowIfNull(node);
node.IsNative = isNative;
@@ -161,7 +128,10 @@ namespace StgSharp.PipeLine
_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.");
@@ -171,7 +141,9 @@ namespace StgSharp.PipeLine
return node;
}
public PipelineNode GetNode(PipelineNodeLabel label)
public PipelineNode GetNode(
PipelineNodeLabel label
)
{
if (_allNode.TryGetValue(label, out PipelineNode? node))
{
@@ -182,14 +154,19 @@ namespace StgSharp.PipeLine
}
}
public void LinkToInput(PipelineNodeInPort port)
public void LinkToInput(
PipelineNodeInPort port
)
{
ArgumentNullException.ThrowIfNull(port);
PipelineNodeOutPort p = _beginning.DefaultOut;
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);
@@ -197,7 +174,9 @@ namespace StgSharp.PipeLine
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetInput(params (string label, IPipeLineConnectionPayload arg)[] parameters)
public void SetInput(
params (string label, IPipeLineConnectionPayload arg)[] parameters
)
{
_beginning.SetInputData(parameters);
}
@@ -211,7 +190,8 @@ namespace StgSharp.PipeLine
public bool TryGetAllNode(
out List<List<PipelineNode>> mainThreadNodes,
out List<List<PipelineNode>> concurrentNodes)
out List<List<PipelineNode>> concurrentNodes
)
{
if (_isAvailable)
{
@@ -224,7 +204,9 @@ namespace StgSharp.PipeLine
return false;
}
internal bool RequestNexConcurrentNode(out PipelineNode node)
internal bool RequestNexConcurrentNode(
out PipelineNode node
)
{
int index, level;
if (cLevel >= _concurrentNodes.Count)
@@ -251,7 +233,9 @@ namespace StgSharp.PipeLine
return true;
}
internal bool RequestNextMainThreadNode(out PipelineNode node)
internal bool RequestNextMainThreadNode(
out PipelineNode node
)
{
if (mtLevel >= _mainThreadNodes.Count)
{
@@ -280,7 +264,8 @@ 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);
+18 -29
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
@@ -45,7 +25,10 @@ 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;
@@ -62,7 +45,9 @@ 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) {
return;
@@ -75,7 +60,9 @@ namespace StgSharp.PipeLine
}
}
public static void WaitAll(Dictionary<string, PipelineConnector> ports)
public static void WaitAll(
Dictionary<string, PipelineConnector> ports
)
{
if (ports == null) {
return;
@@ -110,7 +97,9 @@ namespace StgSharp.PipeLine
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CompleteAndWriteData(IPipeLineConnectionPayload args)
public void CompleteAndWriteData(
IPipeLineConnectionPayload args
)
{
this.args = args;
CompleteAndSkip();
+18 -32
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// 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:
//
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -43,9 +23,11 @@ namespace StgSharp.PipeLine
private PipelineScheduler _bp;
public BeginningNode(PipelineScheduler bp)
: base(
DefaultOperation, new PipelineNodeStringLabel("BeginningNode"), true, [ "default" ],[ OutName ])
public BeginningNode(
PipelineScheduler bp
)
: base(DefaultOperation, new PipelineNodeStringLabel("BeginningNode"), true,
["default"], [OutName])
{
_bp = bp;
}
@@ -58,7 +40,9 @@ namespace StgSharp.PipeLine
PipelineNodeOutPort.SkipAll(_output);
}
internal void SetInputData(IEnumerable<(string, IPipeLineConnectionPayload)> data)
internal void SetInputData(
IEnumerable<(string, IPipeLineConnectionPayload)> data
)
{
if (data is null) {
return;
@@ -75,9 +59,11 @@ namespace StgSharp.PipeLine
private PipelineScheduler _bp;
public EndingNode(PipelineScheduler bp)
: base(
DefaultOperation, name:new PipelineNodeStringLabel("EndingNode"), true, [ "default" ],[ "default" ])
public EndingNode(
PipelineScheduler bp
)
: base(DefaultOperation, name:new PipelineNodeStringLabel("EndingNode"), true,
["default"], ["default"])
{
_bp = bp;
}