|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | tqAdd(tq, task) taskqueueAdd(tq, task) |
| #define | tqRun(tq, ptask) |
| #define | tqSchedule(tq, task, delay) _tqSchedule(tq, ComplexTask(task), delay) |
| #define | tqDefer(tq, task) _tqDefer(tq, ComplexTask(task)) |
Functions | |
| bool | tqCall (TaskQueue *tq, closure cls) |
| int32 | tqWorkers (TaskQueue *tq) |
| #define tqAdd | ( | tq, | |
| task | |||
| ) | taskqueueAdd(tq, task) |
bool tqAdd(TaskQueue *tq, BasicTask *task)
Add a task to the queue to run immediately. The caller retains ownership of the task reference.
Definition at line 127 of file taskqueue.h.
| #define tqDefer | ( | tq, | |
| task | |||
| ) | _tqDefer(tq, ComplexTask(task)) |
bool tqDefer(TaskQueue *tq, ComplexTask *task)
Add a task to the queue but defer it indefinitely. Task will not run until explicitly advanced with taskAdvance() or ctaskAdvance(). Useful for tasks waiting on external events.
| tq | Task queue (must support complex tasks) |
| task | Complex task to defer |
Definition at line 173 of file taskqueue.h.
| #define tqRun | ( | tq, | |
| ptask | |||
| ) |
void tqRun(TaskQueue *tq, BasicTask **ptask)
Convenience function to add a task to the queue and release it. This is the most common pattern for fire-and-forget tasks.
| tq | Task queue to run task on |
| ptask | Pointer to task pointer (task is released after adding) |
Definition at line 135 of file taskqueue.h.
| #define tqSchedule | ( | tq, | |
| task, | |||
| delay | |||
| ) | _tqSchedule(tq, ComplexTask(task), delay) |
bool tqSchedule(TaskQueue *tq, ComplexTask *task, int64 delay)
Add a task to the queue to run after a delay. Requires a ComplexTask-derived task and a ComplexTaskQueue.
| tq | Task queue (must support complex tasks) |
| task | Complex task to schedule |
| delay | Delay in system time units before task should run |
Definition at line 156 of file taskqueue.h.
| bool tqCall | ( | TaskQueue * | tq, |
| closure | cls | ||
| ) |
Runs a closure on a thread in a task queue's worker pool.
A simplified interface for cases where creating a task class is overkill. The closure is called with the queue it is running on: closureCall(cls, stvar(object, tq)). Returning false from it marks the task failed.
Anything the closure needs is captured when it is created, and released with it, so there is no separate context pointer to clean up:
Takes ownership of the closure whatever happens: it is destroyed once the task has run, when the task is cancelled or the queue shuts down without running it, and before this returns if the task could not be queued at all. Do not destroy it afterwards.
| tq | Task queue to run the closure on |
| cls | Closure to execute; ownership passes to the queue |
| int32 tqWorkers | ( | TaskQueue * | tq | ) |
int32 tqWorkers(TaskQueue *tq)
Returns the current number of worker threads in the queue's pool. For manual queues, returns 0.
| tq | Task queue to query |