|
Peano
|
Spawned node. More...
#include <dynamic_task_graph_spawned_node.h>

Public Types | |
| enum class | State { Submitted , Spawned , Complete } |
Public Member Functions | |
| dynamic_task_graph_spawned_node (const dynamic_task_graph_node &task_specification, dynamic_task_graph &task_graph) | |
| Create a new task node in the graph. | |
| dynamic_task_graph_spawned_node (const dynamic_task_graph_spawned_node &)=delete | |
| You cannot copy a spawned node. | |
| void | incoming_task_has_terminated () |
| Decrement the incoming task counter and run if now ready. | |
| void | add_incoming_task_dependency () |
| void | run () |
| Run the task. | |
| std::string | to_string () const |
| Helper routine, which likely will not be there in TBB counterpart. | |
| bool | add_successor (std::shared_ptr< dynamic_task_graph_spawned_node > successor) |
| bool | has_terminated () const |
Private Attributes | |
| State | _state |
| std::function< void()> | _functor |
| tbb::spin_mutex | _dependencies_semaphore |
| Semaphore over all the dependencies. | |
| dynamic_task_graph & | _task_graph |
| int | _number_of_in_dependencies |
| std::vector< std::shared_ptr< dynamic_task_graph_spawned_node > > | _out_dependency |
Spawned node.
This class is only used internally within the task graph lib and not to be used directly by users. Users create instances of dynamic_task_graph_node. Once they put this node into a task_graph instance, it is tied to a new instance of spawned_task_graph_node.
As long as a task graph is alive, users might use it to introduce new task dependencies. So we have to ensure that the memory location is absolutely unique. Notably, we may not encounter a situation where a user submits a task A, this task is processed immediately, then creates a task B and a task C which depends on A (but not B). So B may never ever end up at the same memory location as A.
To avoid this, we work exclusively with smart pointers referencing spawned nodes.
Definition at line 46 of file dynamic_task_graph_spawned_node.h.
|
strong |
Definition at line 48 of file dynamic_task_graph_spawned_node.h.
| tbb::dynamic_task_graph_spawned_node::dynamic_task_graph_spawned_node | ( | const dynamic_task_graph_node & | task_specification, |
| dynamic_task_graph & | task_graph | ||
| ) |
Create a new task node in the graph.
Creating a new task node means that we have to "invert" the edges in the underlying graph: An instance of task_specification knows which task are incoming. For the actual task graph, we need the outgoing tasks.
The default spawned task has one incoming dependency, i.e. is not ready. You have to manually decrease the counter after construction once all dependencies are in place.
|
delete |
You cannot copy a spawned node.
| void tbb::dynamic_task_graph_spawned_node::add_incoming_task_dependency | ( | ) |
| bool tbb::dynamic_task_graph_spawned_node::add_successor | ( | std::shared_ptr< dynamic_task_graph_spawned_node > | successor | ) |
| bool tbb::dynamic_task_graph_spawned_node::has_terminated | ( | ) | const |
| void tbb::dynamic_task_graph_spawned_node::incoming_task_has_terminated | ( | ) |
Decrement the incoming task counter and run if now ready.
We first decrement the incoming task counter. This part has to be protected with a semaphore, so no two threads can decrement the task at the same time. While we decrement the task, we can check if it is ready.
If a task is ready, we can actually run() it.
| void tbb::dynamic_task_graph_spawned_node::run | ( | ) |
Run the task.
This is the actual routine which hands the task over to TBB's runtime. The system is allowed to invoke it if and only if the task is ready, i.e. has no pending incoming dependencies anymore.
We work with catch by reference here, as we know that all the task's fields are still alive while we execute the task.
| std::string tbb::dynamic_task_graph_spawned_node::to_string | ( | ) | const |
Helper routine, which likely will not be there in TBB counterpart.
|
private |
Semaphore over all the dependencies.
These are held in a container and hence need a proper mutex. All other states are realised as atomics to minimise locking.
Definition at line 165 of file dynamic_task_graph_spawned_node.h.
|
private |
Definition at line 158 of file dynamic_task_graph_spawned_node.h.
Referenced by tarch.plotter.api.filters.Calculator.Calculator::render().
|
private |
Definition at line 167 of file dynamic_task_graph_spawned_node.h.
|
private |
Definition at line 168 of file dynamic_task_graph_spawned_node.h.
|
private |
Definition at line 157 of file dynamic_task_graph_spawned_node.h.
|
private |
Definition at line 166 of file dynamic_task_graph_spawned_node.h.