NAME
ttypt/stl_job.h - Generic message-passing multi-core compute worker pool for libstele.
SYNOPSIS
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include 'iso.h'
Typedefs
Pure deterministic compute entry point for a job.
Functions
Initialize the global compute worker pool.
Query the number of active background compute workers (0 = cooperative).
Submit an asynchronous compute job.
Non-blocking status check for a submitted job.
Retrieve the output of a completed job and release its slot.
Cooperatively execute up to max_jobs queued jobs on the caller thread.
Drain background workers, free all pending/unclaimed job slots, and reset the pool so stl_job_init() may be called again.
Detailed Description
Generic message-passing multi-core compute worker pool for libstele.
Dispatches pure deterministic compute jobs (kind, in_buf) -> out_buf off the caller thread without requiring SharedArrayBuffer:
- Native (POSIX / Win32): runs native_exec on a persistent stl_wq_t thread pool (or a local cooperative ring when max_workers == 0).
- WebAssembly (__wasm__): delegates to a host-managed pool of lightweight Web Workers running a compute-only WASM module (worker_url) connected via direct MessageChannel ports with zero-copy ArrayBuffer transfers. Automatically falls back to a local cooperative ring (stl_job_step) if the host cannot spawn compute workers.
Typedef Documentation
typedef int32_t(* stl_job_exec_fn) (uint32_t kind, const void *in_buf, uint32_t in_len, void *out_buf, uint32_t out_cap)
Pure deterministic compute entry point for a job. Writes at most out_cap bytes into out_buf and returns the byte count written (>= 0), or a negative value on error.
Function Documentation
STL_JOB_API int stl_job_init (const char * worker_url, unsigned int max_workers, stl_job_exec_fn native_exec)
Initialize the global compute worker pool. Idempotent if already initialized.
- worker_url: URL of the compute-only WASM module (used on __wasm__; ignored on native builds).
- max_workers: Maximum worker threads/Web Workers to spawn. Pass 0 to run strictly in cooperative single-threaded mode (stl_job_step).
- native_exec: Function executed on native worker threads and in WASM cooperative fallback mode.
Returns 0 on success, -1 on error.
STL_JOB_API unsigned int stl_job_step (unsigned int max_jobs)
Cooperatively execute up to max_jobs queued jobs on the caller thread. No-op (returns 0) when background workers are active. Used to guarantee bounded per-frame forward progress when stl_job_worker_count() == 0.
STL_JOB_API stl_job_id_t stl_job_submit (uint32_t kind, const void * in_buf, uint32_t in_len, uint32_t out_cap)
Submit an asynchronous compute job. Copies in_len bytes from in_buf (if non-NULL) and reserves out_cap bytes for the result. Returns a non-zero stl_job_id_t on success, or 0 if the pool is uninitialized or saturated.
STL_JOB_API int32_t stl_job_take (stl_job_id_t id, void * dst, uint32_t dst_cap)
Retrieve the output of a completed job and release its slot.
- If the job is STL_JOB_READY, copies min(result_len, dst_cap) bytes into dst (when dst != NULL && dst_cap > 0), frees the job slot, and returns the total output byte count (>= 0).
- If the job is STL_JOB_ERROR, frees the job slot and returns -1.
- If the job is still STL_JOB_PENDING or invalid, leaves the slot untouched and returns -1.
Author
Generated automatically by Doxygen for stele from the source code.