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>
Public Functions
Section titled “Public Functions”| 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 |
Public Attributes
Section titled “Public Attributes”| 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::string | name Debug name for the node. |
| std::optional< uint32_t > | maxReschedules Optional maximum reschedule limit. |
| bool | isYieldable Is this a yieldable node? |
| WorkContractHandle | handle Handle to the work contract (when scheduled). |
| std::atomic< uint32_t > | failedParentCount Number of failed parents (for optimized parent checking). |
| ExecutionType | executionType Execution type for this node (main thread or any thread). |
| std::atomic< bool > | completionProcessed Track if completion has been processed to prevent double processing. |
Detailed Description
Section titled “Detailed Description”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 directlyauto node = graph.addNode([]{ processData();}, "data-processor");
// Or create a yieldable nodeauto yieldNode = graph.addYieldableNode([]() -> WorkResultContext { if (!ready()) return WorkResultContext::yield(); process(); return WorkResultContext::complete();}, "yielder");Public Functions Documentation
Section titled “Public Functions Documentation”function operator=
Section titled “function operator=”inline WorkGraphNode & operator=( WorkGraphNode && other)function operator=
Section titled “function operator=”WorkGraphNode & operator=( const WorkGraphNode &) =deletefunction WorkGraphNode
Section titled “function WorkGraphNode”WorkGraphNode() =defaultfunction WorkGraphNode
Section titled “function WorkGraphNode”inline WorkGraphNode( std::function< void()> w, const std::string & n, ExecutionType execType =ExecutionType::AnyThread)function WorkGraphNode
Section titled “function WorkGraphNode”inline WorkGraphNode( YieldableWorkFunction w, const std::string & n, ExecutionType execType =ExecutionType::AnyThread)function WorkGraphNode
Section titled “function WorkGraphNode”inline WorkGraphNode( WorkGraphNode && other)function WorkGraphNode
Section titled “function WorkGraphNode”WorkGraphNode( const WorkGraphNode &) =deletePublic Attributes Documentation
Section titled “Public Attributes Documentation”variable work
Section titled “variable work”std::variant< std::function< void()>, YieldableWorkFunction > work;Work function to execute - now supports both void and WorkResult returns.
variable userData
Section titled “variable userData”void * userData = nullptr;User data pointer for custom context.
variable state
Section titled “variable state”std::atomic< NodeState > state {NodeState::Pending};Atomic state management (replaces completed/cancelled flags).
variable rescheduleCount
Section titled “variable rescheduleCount”std::atomic< uint32_t > rescheduleCount {0};Reschedule tracking for yieldable nodes.
variable pendingDependencies
Section titled “variable pendingDependencies”std::atomic< uint32_t > pendingDependencies {0};Number of uncompleted dependencies.
variable name
Section titled “variable name”std::string name;Debug name for the node.
variable maxReschedules
Section titled “variable maxReschedules”std::optional< uint32_t > maxReschedules;Optional maximum reschedule limit.
variable isYieldable
Section titled “variable isYieldable”bool isYieldable = false;Is this a yieldable node?
variable handle
Section titled “variable handle”WorkContractHandle handle;Handle to the work contract (when scheduled).
variable failedParentCount
Section titled “variable failedParentCount”std::atomic< uint32_t > failedParentCount {0};Number of failed parents (for optimized parent checking).
variable executionType
Section titled “variable executionType”ExecutionType executionType = ExecutionType::AnyThread;Execution type for this node (main thread or any thread).
variable completionProcessed
Section titled “variable completionProcessed”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