Skip to content

EntropyEngine::Core::Concurrency

Name
classEntropyEngine::Core::Concurrency::WorkService
Thread pool service that executes work contracts from multiple groups.
structEntropyEngine::Core::Concurrency::WorkResultContext
Extended result context for yieldable work functions with timing support.
structEntropyEngine::Core::Concurrency::WorkGraphStats
Real-time metrics for your executing workflow - watch the action unfold.
structEntropyEngine::Core::Concurrency::WorkGraphNode
The atomic unit of work in a dependency graph with self-managing execution timing.
structEntropyEngine::Core::Concurrency::WorkGraphEvent
The mother of all WorkGraph events - timestamp and source.
structEntropyEngine::Core::Concurrency::WorkGraphConfig
Configuration parameters and feature toggles for WorkGraph instances.
classEntropyEngine::Core::Concurrency::WorkGraph
Orchestrates complex parallel workflows with automatic dependency management.
structEntropyEngine::Core::Concurrency::WorkContractTag
classEntropyEngine::Core::Concurrency::WorkContractHandle
EntropyObject-stamped handle for work contracts.
classEntropyEngine::Core::Concurrency::WorkContractGroup
Factory and manager for work contracts with lock-free scheduling.
classEntropyEngine::Core::Concurrency::SpinningDirectScheduler
CPU-intensive scheduler that eliminates sleep/wake overhead for benchmarking.
classEntropyEngine::Core::Concurrency::SignalTreeBase
Abstract base class for SignalTree to enable polymorphic usage.
classEntropyEngine::Core::Concurrency::SignalTree
A lock-free binary tree for signal selection and management.
classEntropyEngine::Core::Concurrency::RoundRobinScheduler
Fair round-robin scheduler providing uniform work distribution.
classEntropyEngine::Core::Concurrency::RandomScheduler
The chaos monkey of schedulers - picks groups at random.
classEntropyEngine::Core::Concurrency::NodeStateManager
Centralized state management for WorkGraph nodes.
structEntropyEngine::Core::Concurrency::NodeStateChangedEvent
The workhorse event - tracks every state transition in your workflow.
classEntropyEngine::Core::Concurrency::NodeScheduler
Manages graph node scheduling and overflow handling for work execution.
structEntropyEngine::Core::Concurrency::NodeScheduledEvent
Node has been submitted to the thread pool.
structEntropyEngine::Core::Concurrency::NodeReadyEvent
All dependencies satisfied - this node is ready to rock!
structEntropyEngine::Core::Concurrency::NodeFailedEvent
Uh oh - a node threw an exception.
structEntropyEngine::Core::Concurrency::NodeExecutingEvent
A thread has started running this node’s work.
structEntropyEngine::Core::Concurrency::NodeDeferredEvent
Work queue is full - this node has to wait.
structEntropyEngine::Core::Concurrency::NodeCompletedEvent
Success!
structEntropyEngine::Core::Concurrency::NodeCancelledEvent
A node was cancelled due to upstream failure.
structEntropyEngine::Core::Concurrency::NodeAddedEvent
Fired when a new task joins your workflow.
classEntropyEngine::Core::Concurrency::IWorkScheduler
Abstract interface for work scheduling strategies in the WorkService.
classEntropyEngine::Core::Concurrency::IConcurrencyProvider
Interface for concurrency providers that execute work from WorkContractGroups.
structEntropyEngine::Core::Concurrency::GraphStatsEvent
Periodic health check - current graph statistics.
structEntropyEngine::Core::Concurrency::GraphExecutionStartedEvent
The starting gun - workflow execution begins!
structEntropyEngine::Core::Concurrency::GraphExecutionCompletedEvent
The finish line - all nodes have reached terminal states.
classEntropyEngine::Core::Concurrency::DirectScheduler
The “just give me work!” scheduler - absolute minimum overhead.
structEntropyEngine::Core::Concurrency::DependencyResolvedEvent
One step closer - a parent completed and child’s dependency count dropped.
structEntropyEngine::Core::Concurrency::DependencyAddedEvent
Fired when you wire two nodes together.
classEntropyEngine::Core::Concurrency::AdaptiveRankingScheduler
Adaptive scheduler that learns from workload patterns to optimize distribution.
Name
using std::function< WorkResultContext()>YieldableWorkFunction
Work that can yield/suspend with timing.
enum class uint8_tWorkResult { YieldUntil = 2, Yield = 1, Complete = 0}
Return value from yieldable work functions.
using std::function< void()>WorkFunction
The actual work to execute (legacy).
using std::function< std::unique_ptr< IWorkScheduler >(const IWorkScheduler::Config &)>SchedulerFactory
Factory function type for creating schedulers.
enum classScheduleResult { Scheduled, NotScheduled, Invalid, Executing, AlreadyScheduled}
Result of schedule/unschedule operations.
enum class uint8_tNodeState { Yielded = 7, Scheduled = 2, Ready = 1, Pending = 0, Failed = 5, Executing = 3, Completed = 4, Cancelled = 6}
The lifecycle states of a task node - from birth to completion.
using Graph::AcyclicNodeHandle< WorkGraphNode >NodeHandle
How you reference nodes.
using std::function< void(NodeHandle)>NodeCallback
Callbacks that receive nodes.
enum class uint8_tExecutionType { MainThread = 1, AnyThread = 0}
Defines where a work contract can be executed.
enum class uint8_tExecutionResult { Success = 0, Skipped = 3, Failed = 1, Cancelled = 2}
The final verdict on how a node’s execution went.
enum class uint32_tContractState { Scheduled = 2, Free = 0, Executing = 3, Completed = 4, Allocated = 1}
States that a work contract can be in during its lifecycle.
using std::function< void(ExecutionResult)>CompletionCallback
Notified when work completes.
Name
size_troundUpToPowerOf2(size_t n)
const char *nodeStateToString(NodeState state)
Human-readable state names for logging and debugging.
boolisValidTransition(NodeState from, NodeState to)
Validates state transitions - prevents impossible state changes.
boolisTerminalState(NodeState state)
Check if a node has reached the end of its journey.
using EntropyEngine::Core::Concurrency::YieldableWorkFunction = std::function<WorkResultContext()>;

Work that can yield/suspend with timing.

EnumeratorValueDescription
YieldUntil2Suspend and reschedule at specific time (use WorkResultContext).
Yield1Suspend and reschedule immediately for later execution.
Complete0Work is done, proceed to completion.

Return value from yieldable work functions.

Work functions can now return a status to control their execution flow. Complete means the work is done, Yield means suspend and reschedule later. This enables coroutine-like behavior without actual C++ coroutines.

auto node = graph.addYieldableNode([]() -> WorkResultContext {
if (!dataReady()) {
return WorkResultContext::yield(); // Try again later
}
processData();
return WorkResultContext::complete();
});
using EntropyEngine::Core::Concurrency::WorkFunction = std::function<void()>;

The actual work to execute (legacy).

using EntropyEngine::Core::Concurrency::SchedulerFactory = std::function<std::unique_ptr<IWorkScheduler>(const IWorkScheduler::Config&)>;

Factory function type for creating schedulers.

Enables registration of schedulers by name and dynamic switching between implementations. The factory receives configuration parameters and returns a new scheduler instance.

std::map<std::string, SchedulerFactory> schedulers = {
{"round-robin", [](auto& cfg) { return std::make_unique<RoundRobinScheduler>(cfg); }},
{"adaptive", [](auto& cfg) { return std::make_unique<AdaptiveRankingScheduler>(cfg); }},
{"random", [](auto& cfg) { return std::make_unique<RandomScheduler>(cfg); }}
};
// Create scheduler by name
auto scheduler = schedulers["adaptive"](config);
EnumeratorValueDescription
ScheduledContract is now scheduled (successful schedule operation).
NotScheduledContract is not scheduled (successful unschedule operation).
InvalidInvalid handle provided.
ExecutingCannot modify - currently executing.
AlreadyScheduledContract was already scheduled (schedule operation failed).

Result of schedule/unschedule operations.

EnumeratorValueDescription
Yielded7Suspended execution, will be rescheduled.
Scheduled2Submitted to WorkContractGroup, in queue.
Ready1All dependencies satisfied, waiting for thread.
Pending0Waiting for dependencies - can’t run yet.
Failed5Exception thrown - children will be cancelled.
Executing3Currently running on a worker thread.
Completed4Finished successfully - triggered children.
Cancelled6Skipped due to parent failure - never ran.

The lifecycle states of a task node - from birth to completion.

Every node in your WorkGraph moves through these states as it progresses from “waiting for parents” to “done”. The transitions are carefully controlled to ensure thread safety and proper dependency management.

State flow:

  • Pending → Ready (when all dependencies complete)
  • Ready → Scheduled (when submitted to thread pool)
  • Scheduled → Executing (when thread picks it up)
  • Executing → Completed/Failed/Yielded (based on return value or exceptions)
  • Yielded → Ready (for rescheduling)
  • Any state → Cancelled (if parent fails)

Terminal states (Completed, Failed, Cancelled) are final - no further transitions.

using EntropyEngine::Core::Concurrency::NodeHandle = Graph::AcyclicNodeHandle<WorkGraphNode>;

How you reference nodes.

using EntropyEngine::Core::Concurrency::NodeCallback = std::function<void(NodeHandle)>;

Callbacks that receive nodes.

EnumeratorValueDescription
MainThread1Must run on the main/UI thread.
AnyThread0Runs on any worker thread from the pool.

Defines where a work contract can be executed.

Choose AnyThread for CPU-bound work that can run anywhere. Choose MainThread for UI updates, OpenGL calls, or other operations that must run on a specific thread. Dependencies work seamlessly across execution types.

// Background processing
auto compute = graph.addNode([]{ heavyComputation(); },
"compute", nullptr, ExecutionType::AnyThread);
// UI update that depends on computation
auto update = graph.addNode([]{ updateProgressBar(); },
"update-ui", nullptr, ExecutionType::MainThread);
graph.addDependency(compute, update); // UI waits for computation
EnumeratorValueDescription
Success0Work function completed without throwing.
Skipped3Skipped for other reasons (reserved for future use).
Failed1Work function threw an exception.
Cancelled2Never ran due to parent failure.

The final verdict on how a node’s execution went.

Simple enum to categorize the outcome of node execution. Used in callbacks and events to communicate results without needing to check multiple states.

EnumeratorValueDescription
Scheduled2Contract is scheduled and ready for execution.
Free0Contract slot is available for allocation.
Executing3Contract is currently being executed.
Completed4Contract has completed execution.
Allocated1Contract has been allocated but not scheduled.

States that a work contract can be in during its lifecycle.

using EntropyEngine::Core::Concurrency::CompletionCallback = std::function<void(ExecutionResult)>;

Notified when work completes.

static size_t roundUpToPowerOf2(
size_t n
)
inline const char * nodeStateToString(
NodeState state
)

Human-readable state names for logging and debugging.

Parameters:

  • state The state to stringify

Return: Static string representation (no allocation)

LOG_DEBUG("Node {} transitioned to {}",
node.getData()->name,
nodeStateToString(node.getData()->state));
inline bool isValidTransition(
NodeState from,
NodeState to
)

Validates state transitions - prevents impossible state changes.

Parameters:

  • from Current state
  • to Desired new state

Return: true if the transition is legal

Valid transitions:

  • Pending → Ready or Cancelled
  • Ready → Scheduled or Cancelled
  • Scheduled → Executing or Cancelled
  • Executing → Completed, Failed, or Yielded
  • Yielded → Ready (for rescheduling)
  • Terminal states → Nothing
inline bool isTerminalState(
NodeState state
)

Check if a node has reached the end of its journey.

Parameters:

  • state The state to check

Return: true if this is a final state

Terminal states (Completed, Failed, Cancelled) are final. Yielded is NOT terminal - the node will resume execution.


Updated on 2026-01-26 at 17:14:35 -0500