.TH "ttypt/stl_job.h" 3 "stele" \" -*- nroff -*- .ad l .nh .SH NAME ttypt/stl_job.h \- Generic message-passing multi-core compute worker pool for libstele\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include 'iso\&.h'\fP .br .SS "Typedefs" .in +1c .ti -1c .RI "typedef int32_t(* \fBstl_job_exec_fn\fP) (uint32_t kind, const void *in_buf, uint32_t in_len, void *out_buf, uint32_t out_cap)" .br .RI "Pure deterministic compute entry point for a job\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "STL_JOB_API int \fBstl_job_init\fP (const char *worker_url, unsigned int max_workers, \fBstl_job_exec_fn\fP native_exec)" .br .RI "Initialize the global compute worker pool\&. " .ti -1c .RI "STL_JOB_API unsigned int \fBstl_job_worker_count\fP (void)" .br .RI "Query the number of active background compute workers (0 = cooperative)\&. " .ti -1c .RI "STL_JOB_API stl_job_id_t \fBstl_job_submit\fP (uint32_t kind, const void *in_buf, uint32_t in_len, uint32_t out_cap)" .br .RI "Submit an asynchronous compute job\&. " .ti -1c .RI "STL_JOB_API stl_job_status_t \fBstl_job_poll\fP (stl_job_id_t id)" .br .RI "Non-blocking status check for a submitted job\&. " .ti -1c .RI "STL_JOB_API int32_t \fBstl_job_take\fP (stl_job_id_t id, void *dst, uint32_t dst_cap)" .br .RI "Retrieve the output of a completed job and release its slot\&. " .ti -1c .RI "STL_JOB_API unsigned int \fBstl_job_step\fP (unsigned int max_jobs)" .br .RI "Cooperatively execute up to \fRmax_jobs\fP queued jobs on the caller thread\&. " .ti -1c .RI "STL_JOB_API void \fBstl_job_shutdown\fP (void)" .br .RI "Drain background workers, free all pending/unclaimed job slots, and reset the pool so \fR\fBstl_job_init()\fP\fP may be called again\&. " .in -1c .SH "Detailed Description" .PP Generic message-passing multi-core compute worker pool for libstele\&. Dispatches pure deterministic compute jobs \fR(kind, in_buf) -> out_buf\fP off the caller thread without requiring SharedArrayBuffer: .IP "\(bu" 2 Native (POSIX / Win32): runs \fRnative_exec\fP on a persistent \fRstl_wq_t\fP thread pool (or a local cooperative ring when \fRmax_workers == 0\fP)\&. .IP "\(bu" 2 WebAssembly (\fR__wasm__\fP): delegates to a host-managed pool of lightweight Web Workers running a compute-only WASM module (\fRworker_url\fP) connected via direct MessageChannel ports with zero-copy ArrayBuffer transfers\&. Automatically falls back to a local cooperative ring (\fR\fBstl_job_step\fP\fP) if the host cannot spawn compute workers\&. .PP .SH "Typedef Documentation" .PP .SS "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)" .PP Pure deterministic compute entry point for a job\&. Writes at most \fRout_cap\fP bytes into \fRout_buf\fP and returns the byte count written (\fR>= 0\fP), or a negative value on error\&. .SH "Function Documentation" .PP .SS "STL_JOB_API int stl_job_init (const char * worker_url, unsigned int max_workers, \fBstl_job_exec_fn\fP native_exec)" .PP Initialize the global compute worker pool\&. Idempotent if already initialized\&. .IP "\(bu" 2 \fRworker_url\fP: URL of the compute-only WASM module (used on \fR__wasm__\fP; ignored on native builds)\&. .IP "\(bu" 2 \fRmax_workers\fP: Maximum worker threads/Web Workers to spawn\&. Pass \fR0\fP to run strictly in cooperative single-threaded mode (\fR\fBstl_job_step\fP\fP)\&. .IP "\(bu" 2 \fRnative_exec\fP: Function executed on native worker threads and in WASM cooperative fallback mode\&. .PP .PP Returns 0 on success, -1 on error\&. .SS "STL_JOB_API unsigned int stl_job_step (unsigned int max_jobs)" .PP Cooperatively execute up to \fRmax_jobs\fP queued jobs on the caller thread\&. No-op (returns 0) when background workers are active\&. Used to guarantee bounded per-frame forward progress when \fR\fBstl_job_worker_count()\fP == 0\fP\&. .SS "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)" .PP Submit an asynchronous compute job\&. Copies \fRin_len\fP bytes from \fRin_buf\fP (if non-NULL) and reserves \fRout_cap\fP bytes for the result\&. Returns a non-zero \fRstl_job_id_t\fP on success, or \fR0\fP if the pool is uninitialized or saturated\&. .SS "STL_JOB_API int32_t stl_job_take (stl_job_id_t id, void * dst, uint32_t dst_cap)" .PP Retrieve the output of a completed job and release its slot\&. .IP "\(bu" 2 If the job is \fRSTL_JOB_READY\fP, copies \fRmin(result_len, dst_cap)\fP bytes into \fRdst\fP (when \fRdst != NULL && dst_cap > 0\fP), frees the job slot, and returns the total output byte count (\fR>= 0\fP)\&. .IP "\(bu" 2 If the job is \fRSTL_JOB_ERROR\fP, frees the job slot and returns \fR-1\fP\&. .IP "\(bu" 2 If the job is still \fRSTL_JOB_PENDING\fP or invalid, leaves the slot untouched and returns \fR-1\fP\&. .PP .SH "Author" .PP Generated automatically by Doxygen for stele from the source code\&.