|
cwist
Modern C web framework with libttak runtime
|
BSD kqueue backend for the generic CWIST job queue interface. More...
#include <cwist/sys/io/cwist_io.h>#include <cwist/core/mem/alloc.h>#include <cwist/core/mem/gc.h>#include <sys/types.h>#include <sys/event.h>#include <sys/time.h>#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <errno.h>#include <stdatomic.h>#include <stdint.h>#include <time.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
| #define | KQ_WAKE_IDENT 0 |
Functions | |
| cwist_io_queue * | cwist_io_queue_create (size_t capacity) |
| Allocate a kqueue-backed IO queue wrapper. | |
| bool | cwist_io_queue_submit (cwist_io_queue *q, cwist_job_func func, void *arg) |
| Enqueue one callback by triggering an EVFILT_USER event. | |
| void | cwist_io_queue_run (cwist_io_queue *q) |
| Process 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) |
| Free jobs nobody ran, close the kqueue descriptor, free the queue. | |
BSD kqueue backend for the generic CWIST job queue interface.
Definition in file kqueue.c.
| cwist_io_queue * cwist_io_queue_create | ( | size_t | capacity | ) |
Allocate a kqueue-backed IO queue wrapper.
Initialize the job queue.
| capacity | Capacity hint accepted for interface parity and currently unused. |
Definition at line 36 of file kqueue.c.
References cap, cwist_alloc(), cwist_free(), cwist_full_gc_enabled(), cwist_gc_scope_disown(), and KQ_WAKE_IDENT.
Referenced by cwist_scheduler_create().
| void cwist_io_queue_destroy | ( | cwist_io_queue * | q | ) |
Free jobs nobody ran, close the kqueue descriptor, free the queue.
Destroy the queue and free resources.
All runners are gone by contract (stop, then join, then destroy).
| q | Queue handle to destroy. |
Definition at line 185 of file kqueue.c.
References cap, cwist_free(), and KQ_WAKE_IDENT.
Referenced by cwist_scheduler_create(), and cwist_scheduler_destroy().
| void cwist_io_queue_run | ( | cwist_io_queue * | q | ) |
Process queued jobs until shutdown is requested and no work remains.
Run the event loop. Blocks indefinitely, processing jobs as they complete/trigger.
| q | Kqueue-backed queue handle. |
Definition at line 119 of file kqueue.c.
References cap, cwist_free(), cwist_full_gc_enabled(), cwist_gc_scope_flush(), and KQ_WAKE_IDENT.
| 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.
Runners finish the jobs already submitted, then return. The descriptor stays open until cwist_io_queue_destroy(), so a runner blocked in kevent() is woken by the wake event rather than by a close() that BSD kernels need not notice.
| q | Queue handle to stop. |
Definition at line 168 of file kqueue.c.
References cap, and KQ_WAKE_IDENT.
Referenced by cwist_scheduler_destroy().
| bool cwist_io_queue_submit | ( | cwist_io_queue * | q, |
| cwist_job_func | func, | ||
| void * | arg | ||
| ) |
Enqueue one callback by triggering an EVFILT_USER event.
Submit a job to be executed asynchronously.
| q | Kqueue-backed queue handle. |
| func | Callback to execute when the event is consumed. |
| arg | User payload forwarded to func. |
Definition at line 80 of file kqueue.c.
References cap, cwist_alloc(), cwist_free(), cwist_full_gc_enabled(), and cwist_gc_scope_disown().
Referenced by cwist_scheduler_schedule(), and cwist_scheduler_submit().