|
OpenCV for Unity 3.0.3
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.13.0/index.html ) for the details of the argument of the method.
|
Orchestrates at most one in-flight asynchronous Task versus synchronous syncWork, optional host cancellation, and a latest-result buffer for reference-type pipelines.
More...
Public Member Functions | |
| void | Cancel () |
| void | Dispose () |
Cancels in-flight work, clears the task reference without awaiting, and releases latest and async buffers. Does not call disposeAsyncAfterWorkTask. | |
| async ValueTask | DisposeAsync () |
Cancels, awaits the in-flight Task, then awaits the optional disposeAsyncAfterWorkTask callback, then releases state. | |
| void | SubmitWork (TInput[] inputs, Func< TInput[], TResult[]> syncWork, Func< TInput[], Task< TResult[]> > asyncWork) |
Submits inputs for work: syncWork on the caller when UseAsyncWork is false, or a single in-flight asyncWork when true. When true, CopyInputsForAsync is used before asyncWork. syncWork receives inputs as passed in. | |
| bool | TryGetLatestResult (out TResult[] results) |
| Tries to return the latest successful result array. Deriving types can tighten validation via ValidateLatestForTryGet. | |
Protected Member Functions | |
| SingleFlightSyncAsyncRunner (bool useAsyncWork, CancellationToken asyncWorkCancellationToken=default, Func< Task > disposeAsyncAfterWorkTask=null) | |
| Initializes a new runner. Only DisposeAsync runs disposeAsyncAfterWorkTask ; Dispose does not. | |
| void | CopyInputsForAsync (TInput[] source, TInput[] destination) |
| Snapshots source into destination (async path only). The arrays are the same length; buffer allocation is handled by EnsureAsyncInputBuffer / overrides. | |
| virtual void | EnsureAsyncInputBuffer (int requiredLength) |
| Ensures the internal buffer used for async input snapshots has length requiredLength . | |
| virtual void | ReleaseAsyncInputBuffers () |
Releases per-element resources held in EnsureAsyncInputBuffer (e.g. OpenCV Mat slots in a derived type). | |
| virtual void | ReleaseSingleResult (TResult result) |
Disposes a single result element. Default: IDisposable when implemented. | |
| virtual bool | ValidateLatestForTryGet (TResult[] latest) |
Optional extra checks for TryGetLatestResult. The default is true. | |
Properties | |
| CancellationToken | InFlightAsyncWorkCancellationToken [get] |
Cancellation token produced by linking the constructor cancellation token with the runner local cancellation token while an asynchronous asyncWork delegate is executing. Outside that window (including the synchronous path), this is default. | |
| bool | IsWorkInFlight [get] |
true while a previously started asynchronous Task is still in progress (not yet completed, faulted, or canceled). When true, SubmitWork will not start new work. | |
| bool | UseAsyncWork [get, set] |
When true, at most one async task runs; a new one starts only when the previous task has completed. When false, SubmitWork runs syncWork on the caller thread (after any still-running asynchronous task from a prior async mode has finished; see IsWorkInFlight and SubmitWork remarks). | |
Events | |
| Action< WorkCompletion< TResult > > | WorkCompleted |
| Occurs when a submitted work unit completes (success, cancellation, or fault), on the thread that completed the operation. | |
Orchestrates at most one in-flight asynchronous Task versus synchronous syncWork, optional host cancellation, and a latest-result buffer for reference-type pipelines.
TInput and TResult are constrained to reference types. The async path does not copy inputs by itself; override CopyInputsForAsync to snapshot inputs before asyncWork runs (for example OpenCV Mat via copyTo in a derived type).
IMPORTANT:
false: SubmitWork runs syncWork on the caller thread (after any still-running async task from a prior async mode has finished).true: SubmitWork starts at most one asyncWork Task; while IsWorkInFlight is true, further SubmitWork calls are ignored.syncWork with a still-running asyncWork (for example shared DNN Net or buffers).asyncWorkCancellationToken); it is linked with a per-runner local token for each async submission.asyncWork, pass InFlightAsyncWorkCancellationToken to APIs that accept a CancellationToken (it is only non-default while asyncWork is executing). Do not rely on it from syncWork.Dispose returned elements unless you have copied ownership off—see TryGetLatestResult remarks.await so the optional disposeAsyncAfterWorkTask runs after the in-flight task.await continuation thread; when SubmitWork is called from the Unity main thread, await asyncWork(...).ConfigureAwait(true) typically resumes on the captured System.Threading.SynchronizationContext (often the main thread), but this is not guaranteed. Do not use Unity main-thread-only APIs in the handler unless you know the completion thread; marshal if needed.Results elements in the handler; ownership matches TryGetLatestResult.null outputs.Example Usage:
| TInput | : | class | |
| TResult | : | class |
|
protected |
Initializes a new runner. Only DisposeAsync runs disposeAsyncAfterWorkTask ; Dispose does not.
| useAsyncWork | Initial async (non-in-flight) mode. |
| asyncWorkCancellationToken | Token that cancels the linked work scope; combined with the local token used by Cancel and UseAsyncWork changes. |
| disposeAsyncAfterWorkTask | Optional async cleanup after the in-flight Task (e.g. async () => { await a.WaitForCompletionTaskAsync(); await b.WaitForCompletionTaskAsync(); }). |
| void OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.Cancel | ( | ) |
|
abstractprotected |
Snapshots source into destination (async path only). The arrays are the same length; buffer allocation is handled by EnsureAsyncInputBuffer / overrides.
| void OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.Dispose | ( | ) |
Cancels in-flight work, clears the task reference without awaiting, and releases latest and async buffers. Does not call disposeAsyncAfterWorkTask.
| async ValueTask OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.DisposeAsync | ( | ) |
Cancels, awaits the in-flight Task, then awaits the optional disposeAsyncAfterWorkTask callback, then releases state.
|
protectedvirtual |
Ensures the internal buffer used for async input snapshots has length requiredLength .
|
protectedvirtual |
Releases per-element resources held in EnsureAsyncInputBuffer (e.g. OpenCV Mat slots in a derived type).
|
protectedvirtual |
Disposes a single result element. Default: IDisposable when implemented.
| void OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.SubmitWork | ( | TInput[] | inputs, |
| Func< TInput[], TResult[]> | syncWork, | ||
| Func< TInput[], Task< TResult[]> > | asyncWork ) |
Submits inputs for work: syncWork on the caller when UseAsyncWork is false, or a single in-flight asyncWork when true. When true, CopyInputsForAsync is used before asyncWork. syncWork receives inputs as passed in.
If a previous asynchronous Task is still in progress (IsWorkInFlight is true), this method does nothing: neither syncWork nor a new asyncWork is started. That keeps at most one async job in flight and avoids overlapping synchronous work with a still-running async job (e.g. shared Net or buffers). TryGetLatestResult still reflects the last completed work when a submission is skipped.
| inputs | Input batch (not null, non-empty). |
| syncWork | Synchronous work (not null when UseAsyncWork is false). |
| asyncWork | Asynchronous work (not null when UseAsyncWork is true); no CancellationToken parameter—use InFlightAsyncWorkCancellationToken. |
| bool OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.TryGetLatestResult | ( | out TResult[] | results | ) |
Tries to return the latest successful result array. Deriving types can tighten validation via ValidateLatestForTryGet.
Disposal of the latest result buffer (including each element when IDisposable) is this runner's responsibility: it is released when newer results replace it or when this instance is disposed. Do not call Dispose on results or its elements; the same instances remain owned by the runner until then. results is the runner's live buffer: mutating an element in place changes the stored result. If you need to modify it, clone (or copy) the element (or the array) first, then work on the copy.
|
protectedvirtual |
Optional extra checks for TryGetLatestResult. The default is true.
|
get |
Cancellation token produced by linking the constructor cancellation token with the runner local cancellation token while an asynchronous asyncWork delegate is executing. Outside that window (including the synchronous path), this is default.
|
get |
true while a previously started asynchronous Task is still in progress (not yet completed, faulted, or canceled). When true, SubmitWork will not start new work.
|
getset |
When true, at most one async task runs; a new one starts only when the previous task has completed. When false, SubmitWork runs syncWork on the caller thread (after any still-running asynchronous task from a prior async mode has finished; see IsWorkInFlight and SubmitWork remarks).
| Action<WorkCompletion<TResult> > OpenCVForUnity.UnityIntegration.Runner.SingleFlightSyncAsyncRunner< TInput, TResult >.WorkCompleted |
Occurs when a submitted work unit completes (success, cancellation, or fault), on the thread that completed the operation.
For WorkCompletionKind.Succeeded, WorkCompletion<TResult>.Results is the same live buffer as TryGetLatestResult; do not Dispose elements unless ownership has been copied off. Unity objects and UGUI should only be touched from the main thread; marshal from the handler when the completion thread may differ. Handlers receive only the WorkCompletion<TResult> value (no sender argument).