High-performance multi-stage data-processing pipeline.
More...
#include <StormByte/buffer/pipeline.hxx>
High-performance multi-stage data-processing pipeline.
- Overview
- Pipeline manages a sequence of transformation functions (stages). Each stage receives abstract ExternalReader / ExternalWriter interfaces, allowing the Pipeline to choose the concrete buffer implementation for every intermediate step without changing stage code.
- Buffer strategy
- Intermediate stages use the private high-performance LockFreeRing (SPSC lock-free circular buffer).
- Final stage writes into a public Producer (backed by Ring), so the Consumer returned to the caller keeps the full public API and can be shared safely.
- Execution modes (@ref ExecutionMode bitmask)
- Flags are orthogonal and combinable with
operator|:
Sync (0): stages sequential on the caller’s thread; Process blocks.
Async: work runs in background; Process returns immediately.
Parallel: one thread per stage (SPSC intermediates); without Async, Process still joins workers before returning.
Async | Parallel: concurrent stages and non-blocking Process.
- Stage signature
std::shared_ptr<Logger::Log> log);
Abstract interface for reading data from an external or internal source.
Definition external.hxx:55
Abstract interface for writing data to an external or internal sink.
Definition external.hxx:284
When log is not null, Process passes log->Scope("Buffer/Pipeline") so c identifies this module without touching the thread-local component stack. Nested log->Scope("Decode") inside a stage becomes Buffer/Pipeline/Decode (or Multimedia/Buffer/Pipeline/Decode if the caller already scoped the parent module).
- Best practices
- Always call
out.Close() (or out.SetError()) at the end of every stage.
- Prefer
Async | Parallel for multi-stage streaming production workloads.
- Use
Sync for deterministic debugging.
- The returned Consumer is the only synchronization point the caller needs (wait on Consumer::EoF() / Consumer::IsWritable() as appropriate).
- Pass the application or parent-module logger to Process; do not pre-scope
Buffer/Pipeline or the path will be duplicated.
- See also
- ExternalReader, ExternalWriter, Producer, Consumer, LockFreeRing, ExecutionMode
◆ PipeFunction
Signature of a pipeline stage.
Stages receive abstract reader/writer interfaces so the Pipeline can inject LockFreeRing for intermediates and Ring for the final output without changing stage code.
- Parameters
-
| in | Abstract reader for the stage input. |
| out | Abstract writer for the stage output. |
| log | Optional logger (may be null). When set, this is already Scope("Buffer/Pipeline") relative to the logger passed to Process. |
◆ Pipeline() [1/3]
| StormByte::Buffer::Pipeline::Pipeline |
( |
| ) |
|
|
noexcept |
Default construct an empty pipeline (no stages).
◆ Pipeline() [2/3]
| StormByte::Buffer::Pipeline::Pipeline |
( |
const Pipeline & |
other | ) |
|
Copy construct.
- Parameters
-
| other | Source pipeline (only the list of stages is copied; no running background work is shared). |
◆ Pipeline() [3/3]
| StormByte::Buffer::Pipeline::Pipeline |
( |
Pipeline && |
other | ) |
|
|
noexcept |
Move construct.
- Parameters
-
| other | Source pipeline (left in a valid but unspecified state). |
◆ ~Pipeline()
| StormByte::Buffer::Pipeline::~Pipeline |
( |
| ) |
|
|
noexcept |
Destructor.
Joins any running background execution before destroying state.
◆ AddPipe() [1/2]
| void StormByte::Buffer::Pipeline::AddPipe |
( |
const PipeFunction & |
pipe | ) |
|
Append a processing stage (copy).
- Parameters
-
◆ AddPipe() [2/2]
| void StormByte::Buffer::Pipeline::AddPipe |
( |
PipeFunction && |
pipe | ) |
|
Append a processing stage (move).
- Parameters
-
◆ operator=() [1/2]
Copy assignment.
- Parameters
-
| other | Source pipeline (stages only). |
- Returns
- Reference to this pipeline.
◆ operator=() [2/2]
Move assignment.
- Parameters
-
- Returns
- Reference to this pipeline.
◆ Process()
Execute the pipeline.
- Parameters
-
| buffer | Input Consumer for the first stage. |
| mode | Bitmask of ExecutionMode flags (Sync, Async, Parallel, or combinations). |
| log | Optional logger (may be null). When set, every stage receives log->Scope("Buffer/Pipeline"). |
- Returns
- Consumer of the final stage. When
Async is set, the Consumer is available immediately while background work continues; otherwise Process returns only after all stages have finished.
- Note
- Any previous background run is joined before starting a new one.
- See also
- ExecutionMode, HasExecutionFlag(), Consumer, Producer
◆ SetError()
| void StormByte::Buffer::Pipeline::SetError |
( |
| ) |
const |
|
noexcept |
Propagate error state to all internal buffers.
Calls SetError() on every intermediate LockFreeRing and on the final Producer. Waiting stages wake and observe the error condition.
The documentation for this class was generated from the following file: