CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
System Task Queue

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)
 

Detailed Description

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:

// Run a task immediately
MyTask *task = myTaskCreate();
sysqAdd(task);
// Schedule a task for later
MyTask *delayed = myTaskCreate();
// Run a simple function
sysqCall(myCallback, userData);
#define sysqAdd(task)
Definition sysq.h:55
#define sysqSchedule(task, delay)
Definition sysq.h:84
bool sysqCall(UserTaskCB func, void *userdata)
int64 timeFromSeconds(int64 seconds)
Definition time.h:120

Macro Definition Documentation

◆ sysqAdd

#define sysqAdd (   task)    _sysqAdd(BasicTask(task))

bool 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.

Parameters
taskTask to execute (any task type, automatically cast to BasicTask)
Returns
true if the task was successfully added, false on failure

Definition at line 55 of file sysq.h.

◆ sysqDefer

#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.

Parameters
taskTask to defer (must be ComplexTask or derived type)
Returns
true if the task was successfully deferred, false on failure

Definition at line 98 of file sysq.h.

◆ sysqRun

#define sysqRun (   ptask)
Value:
do { \
sysqAdd(*ptask); \
objRelease(ptask); \
} while (0)

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.

Parameters
ptaskPointer to task pointer (will be set to NULL after release)

Definition at line 65 of file sysq.h.

◆ sysqSchedule

#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.

Parameters
taskTask to execute (must be ComplexTask or derived type)
delayTime to wait before running in nanoseconds (use timeFromSeconds(), timeFromMs(), etc.)
Returns
true if the task was successfully scheduled, false on failure

Definition at line 84 of file sysq.h.

Function Documentation

◆ sysqCall()

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.

Parameters
funcCallback function to execute
userdataOptional user data pointer passed to the callback
Returns
true if the callback was successfully queued, false on failure