1#define _POSIX_C_SOURCE 200809L
20typedef struct job_node {
23 _Atomic(
struct job_node *) next;
45 if (!node)
return NULL;
56static void cwist_job_node_destroy(
job_node_t *node) {
66static void cwist_queue_push(cwist_io_queue *q,
job_node_t *node) {
93static bool cwist_queue_pop(cwist_io_queue *q,
cwist_job_func *func,
void **arg) {
107 cwist_job_node_destroy(
head);
116static bool cwist_queue_wait(cwist_io_queue *q) {
162 cwist_job_node_destroy(
stub);
175 if (!q || !func)
return false;
180 job_node_t *node = cwist_job_node_create(func, arg);
181 if (!node)
return false;
182 cwist_queue_push(q, node);
196 if (!cwist_queue_pop(q, &func, &arg)) {
197 if (!cwist_queue_wait(q)) {
237 cwist_job_node_destroy(node);
Memory allocation wrappers backed by libttak.
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
Platform Agnostic Async Job Queue Interface.
void(* cwist_job_func)(void *arg)
Job function signature.
struct cwist_io_queue cwist_io_queue
Opaque handle for the IO Queue. Backend implementation depends on OS (io_uring, kqueue,...
struct job_node job_node_t
struct job_node job_node_t
void cwist_io_queue_run(cwist_io_queue *q)
Drain queued jobs until shutdown is requested and no work remains.
void cwist_io_queue_stop(cwist_io_queue *q)
Request that runners stop without freeing the queue.
void cwist_io_queue_destroy(cwist_io_queue *q)
Stop the queue, wake sleepers, and free every remaining node.
cwist_io_queue * cwist_io_queue_create(size_t capacity)
Allocate a queue instance and install its sentinel node.
bool cwist_io_queue_submit(cwist_io_queue *q, cwist_job_func func, void *arg)
Submit a callback for asynchronous execution by the queue runner.