v1.8 Dependencies
NOTE: Breaking changes to C API
This release of enkiTS adds a major feature - Dependencies, and a minor feature - Completion Actions.
Dependencies introduce an alternative approach to waiting on tasks to create a sequence of tasks, or task graph. See example below along with links.
Completion Actions are dependencies which execute immediatly after a task has completed, and do not add themselves to the task scheduler. They involve less overhead than a normal task, and can be used to delete the completed task as well as themselves as they are not referenced after their completion function is called. See example/CompletionAction.cpp and example/CompletionAction_c.c .
The following breaking changes to the C API were required:
enkiDelete*
functions now require the task scheduler as a parameter.enkiAddTaskSet
replaced withenkiAddTaskSetArgs
so thatenkiAddTaskSet
can be used for a new function which does not set task arguments, intended for use along with the newenkiSetParams*
functions.
Dependency usage in C++:
- full example in example/Dependencies.cpp
- C example in example/Dependencies_c.c
#include "TaskScheduler.h"
enki::TaskScheduler g_TS;
// define a task set, can ignore range if we only do one thing
struct TaskA : enki::ITaskSet {
void ExecuteRange( enki::TaskSetPartition range_, uint32_t threadnum_ ) override {
// do something here, can issue tasks with g_TS
}
};
struct TaskB : enki::ITaskSet {
enki::Dependency m_Dependency;
void ExecuteRange( enki::TaskSetPartition range_, uint32_t threadnum_ ) override {
// do something here, can issue tasks with g_TS
}
};
int main(int argc, const char * argv[]) {
g_TS.Initialize();
// set dependencies once (can set more than one if needed).
TaskA taskA;
TaskB taskB;
taskB.SetDependency( taskB.m_Dependency, &taskA );
g_TS.AddTaskSetToPipe( &taskA ); // add first task, when complete TaskB will run
g_TS.WaitforTask( &taskB ); // wait for last
return 0;
}