.TH "ttypt/wq.h" 3 "stele" \" -*- nroff -*- .ad l .nh .SH NAME ttypt/wq.h \- Cross-platform lock-free workqueue & worker pool for libstele\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include 'iso\&.h'\fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBstl_wq_task\fP" .br .RI "Embeddable zero-allocation workqueue task descriptor\&. " .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef void(* \fBstl_wq_fn\fP) (void *arg)" .br .RI "Task callback signature executed by a workqueue worker or cooperative step\&. " .ti -1c .RI "typedef struct \fBstl_wq_task\fP \fBstl_wq_task_t\fP" .br .RI "Embeddable zero-allocation workqueue task descriptor\&. " .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum \fBstl_wq_state_t\fP " .br .RI "Lifecycle states for a \fR\fBstl_wq_task_t\fP\fP\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "\fBISO_EXPORT\fP (unsigned int, stl_cpu_count, void)" .br .RI "Query the number of hardware logical processors available\&. Returns >= 1 on all platforms\&. " .ti -1c .RI "\fBISO_EXPORT\fP (stl_wq_t *, stl_wq_create, const char *name, unsigned int nthreads, unsigned int ring_cap)" .br .RI "Create a named workqueue with \fRnthreads\fP persistent worker threads and a power-of-two ring buffer of capacity \fRring_cap\fP (default 256 if 0)\&. " .ti -1c .RI "\fBISO_EXPORT\fP (int, stl_wq_submit, stl_wq_t *wq, \fBstl_wq_task_t\fP *task, \fBstl_wq_fn\fP fn, void *arg)" .br .RI "Submit a task to the workqueue\&. " .ti -1c .RI "\fBISO_EXPORT\fP (unsigned int, stl_wq_step, stl_wq_t *wq, unsigned int max_tasks)" .br .RI "Execute up to \fRmax_tasks\fP pending tasks from \fRwq\fP on the calling thread\&. Returns the number of tasks executed\&. " .ti -1c .RI "\fBISO_EXPORT\fP (void, stl_wq_wait, stl_wq_t *wq, \fBstl_wq_task_t\fP *task)" .br .RI "Wait until a specific task has completed (\fRSTL_WQ_DONE\fP or \fRSTL_WQ_IDLE\fP)\&. Cooperatively helps drain the queue while waiting so the caller never deadlocks\&. " .ti -1c .RI "\fBISO_EXPORT\fP (void, stl_wq_drain, stl_wq_t *wq)" .br .RI "Wait until all queued and running tasks in \fRwq\fP have completed\&. " .ti -1c .RI "unsigned int \fBstl_wq_thread_count\fP (const stl_wq_t *wq)" .br .RI "Query the number of active worker threads backing \fRwq\fP (0 = cooperative single-threaded)\&. " .ti -1c .RI "\fBISO_EXPORT\fP (void, stl_wq_destroy, stl_wq_t *wq)" .br .RI "Drain all pending work, stop worker threads, and free \fRwq\fP\&. " .in -1c .SH "Detailed Description" .PP Cross-platform lock-free workqueue & worker pool for libstele\&. Provides a unified, zero-allocation-per-job taskqueue (\fRstl_wq_t\fP) that maps transparently to: .IP "\(bu" 2 POSIX \fRpthread\fP worker pools on Linux, macOS, and BSDs .IP "\(bu" 2 Win32 threads + \fRSRWLOCK\fP / \fRCONDITION_VARIABLE\fP on Windows .IP "\(bu" 2 WebAssembly shared-memory worker pools (\fRSharedArrayBuffer\fP + atomics) with automatic frame-budgeted cooperative fallback (\fRstl_wq_step\fP) on single-core or non-isolated browser contexts\&. .PP .SH "Typedef Documentation" .PP .SS "typedef struct \fBstl_wq_task\fP \fBstl_wq_task_t\fP" .PP Embeddable zero-allocation workqueue task descriptor\&. Embed directly inside your struct (e\&.g\&. \fRar_node_meta_t\fP or \fRblock_bb_cache_slot_t\fP) so submitting jobs requires zero \fRmalloc\fP/\fRfree\fP calls\&. .SH "Function Documentation" .PP .SS "ISO_EXPORT (int , stl_wq_submit , stl_wq_t * wq, \fBstl_wq_task_t\fP * task, \fBstl_wq_fn\fP fn, void * arg)" .PP Submit a task to the workqueue\&. .IP "\(bu" 2 If \fRtask\fP is already \fRSTL_WQ_QUEUED\fP or \fRSTL_WQ_RUNNING\fP, returns 1 (no-op)\&. .IP "\(bu" 2 If the ring is full, executes \fRfn(arg)\fP inline on the caller thread and marks \fRtask->state = STL_WQ_DONE\fP so callers never deadlock or drop work\&. .IP "\(bu" 2 Returns 0 on success, -1 on invalid arguments\&. .PP .SS "ISO_EXPORT (stl_wq_t * , stl_wq_create , const char * name, unsigned int nthreads, unsigned int ring_cap)" .PP Create a named workqueue with \fRnthreads\fP persistent worker threads and a power-of-two ring buffer of capacity \fRring_cap\fP (default 256 if 0)\&. If \fRnthreads == 0\fP, automatically selects a balanced worker count (\fRclamp(stl_cpu_count() - 1, 1, 4)\fP on native, or cooperative / host-backed on WASM)\&. .SH "Author" .PP Generated automatically by Doxygen for stele from the source code\&.