|
cwist
Modern C web framework with libttak runtime
|
Job queue fallback used when no platform-specific async backend is selected. More...
#include <cwist/sys/io/cwist_io.h>#include <cwist/core/mem/alloc.h>#include <pthread.h>#include <stdatomic.h>#include <stdbool.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
Typedefs | |
| typedef struct job_node | job_node_t |
Functions | |
| cwist_io_queue * | cwist_io_queue_create (size_t capacity) |
| Allocate a queue instance and install its sentinel node. | |
| bool | cwist_io_queue_submit (cwist_io_queue *q, cwist_job_func func, void *arg) |
| Submit a callback for asynchronous execution by the queue runner. | |
| void | cwist_io_queue_run (cwist_io_queue *q) |
| Drain queued jobs until shutdown is requested and no work remains. | |
| void | cwist_io_queue_stop (cwist_io_queue *q) |
| Request that runners stop without freeing the queue. | |
| void | cwist_io_queue_destroy (cwist_io_queue *q) |
| Stop the queue, wake sleepers, and free every remaining node. | |
Job queue fallback used when no platform-specific async backend is selected.
A Michael & Scott two-lock queue: producers append under tail_lock and consumers pop under head_lock, around a dummy sentinel node. The lock-free variant needs safe memory reclamation (see io_queue.c), which this portable fallback does without: a node is freed only by a consumer holding head_lock, after it stopped being the sentinel, and no producer reads a node after linking past it, so nothing can still hold a freed node.
Definition in file io_select.c.
Definition at line 1 of file io_select.c.
| typedef struct job_node job_node_t |
| cwist_io_queue * cwist_io_queue_create | ( | size_t | capacity | ) |
Allocate a queue instance and install its sentinel node.
Initialize the job queue.
| capacity | Requested capacity hint. Currently unused by the select fallback. |
Definition at line 133 of file io_select.c.
References cap, cwist_alloc(), and cwist_free().
| void cwist_io_queue_destroy | ( | cwist_io_queue * | q | ) |
Stop the queue, wake sleepers, and free every remaining node.
Destroy the queue and free resources.
| q | Queue instance to destroy. |
Definition at line 224 of file io_select.c.
References cap, and cwist_free().
| void cwist_io_queue_run | ( | cwist_io_queue * | q | ) |
Drain queued jobs until shutdown is requested and no work remains.
Run the event loop. Blocks indefinitely, processing jobs as they complete/trigger.
| q | Queue to run on the current thread. |
Definition at line 190 of file io_select.c.
References cap.
| void cwist_io_queue_stop | ( | cwist_io_queue * | q | ) |
Request that runners stop without freeing the queue.
Request that all runners stop processing without freeing the queue.
| q | Queue instance to stop. |
Definition at line 212 of file io_select.c.
References cap.
| bool cwist_io_queue_submit | ( | cwist_io_queue * | q, |
| cwist_job_func | func, | ||
| void * | arg | ||
| ) |
Submit a callback for asynchronous execution by the queue runner.
Submit a job to be executed asynchronously.
| q | Queue that should own the job. |
| func | Callback to execute. |
| arg | User payload forwarded to func. |
Definition at line 174 of file io_select.c.
References cap.