|
htils 1
A small set of utilities for C programming.
|
Functions | |
| static int | htils_worker_entry (void *arg) |
| The worker entry point / thread lifecycle. | |
| static b32 | htils_worker_start (htils_worker_t *worker, const htils_worker_config_t *config) |
| Starts and initializes a worker. | |
| htils_worker_config_t | htils_worker_config_default (void) |
| Default worker options (Detachable). | |
| b32 | htils_worker_spawn (htils_worker_t *worker, const htils_worker_config_t *config, htils_worker_fn_t fn, void *userdata) |
| Spawns a single-shot worker. | |
| b32 | htils_worker_spawn_task (htils_worker_t *worker, const htils_worker_config_t *config, htils_worker_task_t task, void *userdata) |
| Spawns a sliced worker task. | |
| void | htils_worker_request_stop (htils_worker_t *worker) |
| Ask a worker to stop. | |
| void | htils_worker_set_paused (htils_worker_t *worker, b32 paused) |
| Pause or resume a sliced worker. | |
| b32 | htils_worker_running (const htils_worker_t *worker) |
| Check if a worker is running a task. | |
| b32 | htils_worker_paused (const htils_worker_t *worker) |
| Check if a sliced worker is paused. | |
| b32 | htils_worker_should_stop (const htils_worker_t *worker) |
| Checks whether a stop was requested (Polled by single-shot workers). | |
| void | htils_worker_join (htils_worker_t *worker) |
| Waits for the task to finish. | |
| htils_worker_config_t htils_worker_config_default | ( | void | ) |
Default worker options (Detachable).
|
static |
The worker entry point / thread lifecycle.
Initializes and runs the worker or task, and clears the scratch arena when done.
| arg | The worker to run. |
| void htils_worker_join | ( | htils_worker_t * | worker | ) |
Waits for the task to finish.
Joins the thread. Call exactly once for a non-detached worker; a no-op for detached workers (poll running instead).
| worker | The worker to join. |
| b32 htils_worker_paused | ( | const htils_worker_t * | worker | ) |
Check if a sliced worker is paused.
| worker | The worker to check. |
| void htils_worker_request_stop | ( | htils_worker_t * | worker | ) |
Ask a worker to stop.
Clears the running flag. A sliced task stops at the next slice boundary; a single-shot body observes it via htils_worker_should_stop. Non-blocking.
| worker | The worker to signal. |
| b32 htils_worker_running | ( | const htils_worker_t * | worker | ) |
Check if a worker is running a task.
| worker | The worker to check. |
| void htils_worker_set_paused | ( | htils_worker_t * | worker, |
| b32 | paused ) |
Pause or resume a sliced worker.
While paused, the worker loop parks between slices 'til resumed or stopped. No effect on single-shot workers.
| worker | The worker to pause. |
| paused | Whether to pause (true) or resume (false). |
worker is a valid, running slot. | b32 htils_worker_should_stop | ( | const htils_worker_t * | worker | ) |
Checks whether a stop was requested (Polled by single-shot workers).
| worker | The worker to check. |
| b32 htils_worker_spawn | ( | htils_worker_t * | worker, |
| const htils_worker_config_t * | config, | ||
| htils_worker_fn_t | fn, | ||
| void * | userdata ) |
Spawns a single-shot worker.
Runs fn once on a new thread. The slot must not already be running.
| worker | The slot to initialize. |
| config | Options, or null for defaults. |
| fn | The single-shot function to run. |
| userdata | The task context passed to fn. |
worker is a valid, non-running slot.fn is not null.| b32 htils_worker_spawn_task | ( | htils_worker_t * | worker, |
| const htils_worker_config_t * | config, | ||
| htils_worker_task_t | task, | ||
| void * | userdata ) |
Spawns a sliced worker task.
Runs task in a library-owned loop that checks stop/pause between slices, so the body never polls. task returns HTILS_WORKER_CONTINUE to keep going or HTILS_WORKER_DONE to finish.
| worker | The slot to initialize. |
| config | Options, or null for defaults. |
| task | The sliced task to run. |
| userdata | The task context passed to task. |
worker is a valid, non-running slot.task is not null.
|
static |
Starts and initializes a worker.
Creates a new scratch arena, and starts the worker thread, making sure each required field is set.
| worker | The worker to start. |
| config | Worker options, or null for defaults. |