|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | tqAdd(tq, task) taskqueueAdd(tq, task) |
| #define | tqRun(tq, ptask) do { taskqueueAdd(tq, *ptask); objRelease(ptask); } while(0) |
| #define | tqSchedule(tq, task, delay) _tqSchedule(tq, ComplexTask(task), delay) |
| #define | tqDefer(tq, task) _tqDefer(tq, ComplexTask(task)) |
Typedefs | |
| typedef bool(* | UserTaskCB) (TaskQueue *tq, void *data) |
Functions | |
| bool | tqCall (TaskQueue *tq, UserTaskCB func, void *userdata) |
| 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 126 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 168 of file taskqueue.h.
| #define tqRun | ( | tq, | |
| ptask | |||
| ) | do { taskqueueAdd(tq, *ptask); objRelease(ptask); } while(0) |
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 134 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 151 of file taskqueue.h.
| typedef bool(* UserTaskCB) (TaskQueue *tq, void *data) |
Generic callback mechanism for basic use that doesn't need to create classes. The callback should return true for success, false for failure.
| tq | Task queue the callback is running on |
| data | User-provided data pointer |
Definition at line 175 of file taskqueue.h.
| bool tqCall | ( | TaskQueue * | tq, |
| UserTaskCB | func, | ||
| void * | userdata | ||
| ) |
bool tqCall(TaskQueue *tq, UserTaskCB func, void *userdata)
Runs a custom function on a thread in a task queue's worker pool. This is a simplified interface for cases where creating a task class is overkill.
| tq | Task queue to run callback on |
| func | Callback function to execute |
| userdata | Optional data pointer passed to callback |
| 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 |