|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | sysqAdd(task) _sysqAdd(BasicTask(task)) |
| #define | sysqRun(ptask) |
| #define | sysqSchedule(task, delay) _sysqSchedule(ComplexTask(task), delay) |
| #define | sysqDefer(task) _sysqDefer(ComplexTask(task)) |
Functions | |
| bool | sysqCall (UserTaskCB func, void *userdata) |
Background task queue for asynchronous library operations.
Similar to system threads (systhread), the system queue (sysq) is a task queue for background tasks run asynchronously by the library itself. It provides a convenient way for library code to defer work without requiring the application to manage task queues.
Key features:
Use this for:
For application-level task queues with full control, use TaskQueue directly instead.
Example:
| #define sysqAdd | ( | task | ) | _sysqAdd(BasicTask(task)) |
Add a task to the system queue to run immediately.
The task is queued for execution on the next available worker thread in the system queue's thread pool. The task object is acquired by the queue and will be released when complete.
| #define sysqDefer | ( | task | ) | _sysqDefer(ComplexTask(task)) |
bool sysqDefer(ComplexTask *task)
Add a task to the queue to be held indefinitely until advanced.
The task is added to the queue but not run until explicitly advanced with taskAdvance(). This is useful for tasks that need to wait for external events or conditions. Requires a ComplexTask.
| task | Task to defer (must be ComplexTask or derived type) |
| #define sysqRun | ( | ptask | ) |
void sysqRun(BasicTask **ptask)
Convenience function to queue a task and release the caller's reference.
This is a common pattern where you create a task, queue it, and immediately release your reference since the queue now owns it. This macro does both operations atomically.
| ptask | Pointer to task pointer (will be set to NULL after release) |
| #define sysqSchedule | ( | task, | |
| delay | |||
| ) | _sysqSchedule(ComplexTask(task), delay) |
bool sysqSchedule(ComplexTask *task, int64 delay)
Add a task to the system queue to run after a delay.
The task is held in the queue and executed after the specified delay. Requires a ComplexTask because scheduling uses the internal timing mechanisms only available in complex tasks.
| task | Task to execute (must be ComplexTask or derived type) |
| delay | Time to wait before running in nanoseconds (use timeFromSeconds(), timeFromMs(), etc.) |
| bool sysqCall | ( | UserTaskCB | func, |
| void * | userdata | ||
| ) |
Run a custom function on a worker thread
Executes a simple callback function on one of the system queue's worker threads without requiring a full task object. This is convenient for simple asynchronous operations.
The callback is executed on a thread from the system queue's worker pool. The userdata pointer is passed through to the callback.
| func | Callback function to execute |
| userdata | Optional user data pointer passed to the callback |