|void||cuflow_workers_spawn (int target_count)|
|void||cuflow_workers_spawn_at_least (int target_count)|
|void||cuflow_workers_spawn_at_most (int target_count)|
|void||cuflow_workers_call (cu_clop0(f, void))|
|void||cuflow_workers_call_at (cu_clop(f, void, struct timespec *t_now), struct timespec *t_call)|
|void||cuflow_workers_register_scheduler (cu_clop(sched, void, cu_bool_t))|
This header provides an API to launch one or more worker threads and run functions within them, either as soon as one is idle or at a given time. The main purpose of this is to unify such work in a common framework, so that the same thread(s) can be used, rather than adding new threads for each task. The functions defined here is aimed to be the bare minimum to achieve this. For instance, if you need to know when a callback is finised, you may need to supply it's closure struct with an additional mutex and possibly a condition variable to communicate with consumer(s) of the computation.
This is implemenated purely with POSIX threads, mutices and condition variables, and in particular avoid timers or signals which may cause trouble in a multi-threaded environment.
Wake up any sleeping workers so that they can pick up any new work. You usually don't need to call this, since it's automically called by functions which add new work or unlocks existing work.
|void cuflow_workers_call||(||cu_clop0(f, void)||)|
Call f in one of the worker threads, as soon as one is ready.
|void cuflow_workers_call_at||(||cu_clop(f, void, struct timespec *t_now)||,|
|struct timespec *||t_call|
Call f at absolute
The current number of worker threads.
Indicate that a unit of work signalled with cuflow_workers_incr_pending has been picked up. This is typically called from a custom scheduler.
|void cuflow_workers_register_scheduler||(||cu_clop(sched, void, cu_bool_t)||)|
Arranged for sched to be called round-robin along with other registered work. This can happen either when a task is waiting for work to be completed or directly from a worker thread. When called from a worker thread, true is passed for the first argument. Otherwise, false is passed to indicate that sched is called from an arbitrary subroutine, in which case sched should only do a small amount of work and exit.
Spawn or drop worker threads until there are exactly target_count left. This is not safe to call within worker threads.
Spawns worker threads as needed so that there are at least target_count of them.
Drops worker threads as needed so that there are at most target_count left.
A call to this function performs some work which have been registered by one of the other functions from this header. This is typcially invoked when waiting for resources or results from other scheduled work.