Skip to content

EntropyEngine::Core::Concurrency::WorkGraphNode

EntropyEngine::Core::Concurrency::WorkGraphNode

Section titled “EntropyEngine::Core::Concurrency::WorkGraphNode”

The atomic unit of work in a dependency graph with self-managing execution timing. More…

#include <WorkGraph.h>

Name
WorkGraphNode &operator=(WorkGraphNode && other)
WorkGraphNode &operator=(const WorkGraphNode & ) =delete
WorkGraphNode() =default
WorkGraphNode(std::function< void()> w, const std::string & n, ExecutionType execType =ExecutionType::AnyThread)
WorkGraphNode(YieldableWorkFunction w, const std::string & n, ExecutionType execType =ExecutionType::AnyThread)
WorkGraphNode(WorkGraphNode && other)
WorkGraphNode(const WorkGraphNode & ) =delete
Name
std::variant< std::function< void()>, YieldableWorkFunction >work
Work function to execute - now supports both void and WorkResult returns.
void *userData
User data pointer for custom context.
std::atomic< NodeState >state
Atomic state management (replaces completed/cancelled flags).
std::atomic< uint32_t >rescheduleCount
Reschedule tracking for yieldable nodes.
std::atomic< uint32_t >pendingDependencies
Number of uncompleted dependencies.
std::stringname
Debug name for the node.
std::optional< uint32_t >maxReschedules
Optional maximum reschedule limit.
boolisYieldable
Is this a yieldable node?
WorkContractHandlehandle
Handle to the work contract (when scheduled).
std::atomic< uint32_t >failedParentCount
Number of failed parents (for optimized parent checking).
ExecutionTypeexecutionType
Execution type for this node (main thread or any thread).
std::atomic< bool >completionProcessed
Track if completion has been processed to prevent double processing.
struct EntropyEngine::Core::Concurrency::WorkGraphNode;

The atomic unit of work in a dependency graph with self-managing execution timing.

WorkGraphNode represents a single task within a dependency graph. Each node encapsulates a work function along with the necessary state management to ensure execution occurs precisely when all dependencies are satisfied. The node maintains complete awareness of its position within the execution hierarchy.

The node tracks:

  • Its current state (pending, executing, completed, yielded, etc.)
  • How many parents need to finish before it can run
  • Whether any parent failed (so it should be cancelled)
  • Its work contract handle for execution
  • Reschedule count for yieldable nodes

All state transitions use atomic operations to ensure thread-safe updates when multiple parent nodes complete concurrently. This design enables safe concurrent dependency count decrements without locks.

// Nodes are created internally by WorkGraph::addNode()
// You interact with them through NodeHandle, not directly
auto node = graph.addNode([]{
processData();
}, "data-processor");
// Or create a yieldable node
auto yieldNode = graph.addYieldableNode([]() -> WorkResultContext {
if (!ready()) return WorkResultContext::yield();
process();
return WorkResultContext::complete();
}, "yielder");
inline WorkGraphNode & operator=(
WorkGraphNode && other
)
WorkGraphNode & operator=(
const WorkGraphNode &
) =delete
WorkGraphNode() =default
inline WorkGraphNode(
std::function< void()> w,
const std::string & n,
ExecutionType execType =ExecutionType::AnyThread
)
inline WorkGraphNode(
YieldableWorkFunction w,
const std::string & n,
ExecutionType execType =ExecutionType::AnyThread
)
inline WorkGraphNode(
WorkGraphNode && other
)
WorkGraphNode(
const WorkGraphNode &
) =delete
std::variant< std::function< void()>, YieldableWorkFunction > work;

Work function to execute - now supports both void and WorkResult returns.

void * userData = nullptr;

User data pointer for custom context.

std::atomic< NodeState > state {NodeState::Pending};

Atomic state management (replaces completed/cancelled flags).

std::atomic< uint32_t > rescheduleCount {0};

Reschedule tracking for yieldable nodes.

std::atomic< uint32_t > pendingDependencies {0};

Number of uncompleted dependencies.

std::string name;

Debug name for the node.

std::optional< uint32_t > maxReschedules;

Optional maximum reschedule limit.

bool isYieldable = false;

Is this a yieldable node?

WorkContractHandle handle;

Handle to the work contract (when scheduled).

std::atomic< uint32_t > failedParentCount {0};

Number of failed parents (for optimized parent checking).

ExecutionType executionType = ExecutionType::AnyThread;

Execution type for this node (main thread or any thread).

std::atomic< bool > completionProcessed {false};

Track if completion has been processed to prevent double processing.


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