NAME
ttypt/wq.h - Cross-platform lock-free workqueue & worker pool for libstele.
SYNOPSIS
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdatomic.h>
#include 'iso.h'
Data Structures
Embeddable zero-allocation workqueue task descriptor.
Typedefs
Task callback signature executed by a workqueue worker or cooperative step.
Embeddable zero-allocation workqueue task descriptor.
Enumerations
Lifecycle states for a stl_wq_task_t.
Functions
Query the number of hardware logical processors available. Returns >= 1 on all platforms.
Create a named workqueue with nthreads persistent worker threads and a power-of-two ring buffer of capacity ring_cap (default 256 if 0).
Submit a task to the workqueue.
Execute up to max_tasks pending tasks from wq on the calling thread. Returns the number of tasks executed.
Wait until a specific task has completed (STL_WQ_DONE or STL_WQ_IDLE). Cooperatively helps drain the queue while waiting so the caller never deadlocks.
Wait until all queued and running tasks in wq have completed.
Query the number of active worker threads backing wq (0 = cooperative single-threaded).
Drain all pending work, stop worker threads, and free wq.
Detailed Description
Cross-platform lock-free workqueue & worker pool for libstele.
Provides a unified, zero-allocation-per-job taskqueue (stl_wq_t) that maps transparently to:
- POSIX pthread worker pools on Linux, macOS, and BSDs
- Win32 threads + SRWLOCK / CONDITION_VARIABLE on Windows
- WebAssembly shared-memory worker pools (SharedArrayBuffer + atomics) with automatic frame-budgeted cooperative fallback (stl_wq_step) on single-core or non-isolated browser contexts.
Typedef Documentation
typedef struct stl_wq_task stl_wq_task_t
Embeddable zero-allocation workqueue task descriptor. Embed directly inside your struct (e.g. ar_node_meta_t or block_bb_cache_slot_t) so submitting jobs requires zero malloc/free calls.
Function Documentation
ISO_EXPORT (int , stl_wq_submit , stl_wq_t * wq, stl_wq_task_t * task, stl_wq_fn fn, void * arg)
Submit a task to the workqueue.
- If task is already STL_WQ_QUEUED or STL_WQ_RUNNING, returns 1 (no-op).
- If the ring is full, executes fn(arg) inline on the caller thread and marks task->state = STL_WQ_DONE so callers never deadlock or drop work.
- Returns 0 on success, -1 on invalid arguments.
ISO_EXPORT (stl_wq_t * , stl_wq_create , const char * name, unsigned int nthreads, unsigned int ring_cap)
Create a named workqueue with nthreads persistent worker threads and a power-of-two ring buffer of capacity ring_cap (default 256 if 0). If nthreads == 0, automatically selects a balanced worker count (clamp(stl_cpu_count() - 1, 1, 4) on native, or cooperative / host-backed on WASM).
Author
Generated automatically by Doxygen for stele from the source code.