40 static size_t io_tqueue_dev_cancel(
io_dev_t *dev,
struct ev_task *task);
44 static const struct io_dev_vtbl io_tqueue_dev_vtbl = {
45 &io_tqueue_dev_get_ctx,
46 &io_tqueue_dev_get_exec,
47 &io_tqueue_dev_cancel,
52 static void io_tqueue_svc_shutdown(
struct io_svc *svc);
55 static const struct io_svc_vtbl io_tqueue_svc_vtbl = {
57 &io_tqueue_svc_shutdown
71 unsigned shutdown : 1;
72 unsigned submitted : 1;
77 static void io_tqueue_wait_func(
struct ev_task *task);
82 static void io_tqueue_pop(
87 static inline void io_tqueue_wait_post(
struct io_tqueue_wait *wait,
int errc);
88 static inline size_t io_tqueue_wait_queue_post(
struct sllist *queue,
int errc);
95 static void io_tqueue_async_wait_func(
struct ev_task *
task);
107 io_tqueue_free(
void *ptr)
125 tq->dev_vptr = &io_tqueue_dev_vtbl;
135 tq->exec, &io_tqueue_wait_func);
145 tq->next = (
struct timespec){ 0, 0 };
161 io_tqueue_svc_shutdown(&tq->svc);
189 io_tqueue_t *tmp = io_tqueue_init(tq, timer, exec);
219 return &tq->dev_vptr;
238 task->
exec = tq->exec;
255 task->_data = &tq->queue;
259 if ((!tq->next.tv_sec && !tq->next.tv_nsec)
261 tq->next = wait->
value;
262 struct itimerspec value = { { 0, 0 }, tq->next };
267 tq->next = (
struct timespec){ 0, 0 };
269 io_tqueue_do_pop_wait(tq, &queue, NULL);
273 int submit = !tq->submitted && !
pheap_empty(&tq->queue);
282 io_tqueue_wait_queue_post(&queue, errc);
298 io_tqueue_do_pop_wait(tq, &queue, wait);
317 io_tqueue_do_pop_wait(tq, &queue, wait);
337 async_wait->promise = promise;
340 &io_tqueue_async_wait_func);
345 *pwait = &async_wait->wait;
357 io_tqueue_dev_get_ctx(
const io_dev_t *dev)
365 io_tqueue_dev_get_exec(
const io_dev_t *dev)
380 io_tqueue_pop(tq, &queue, task);
393 io_tqueue_pop(tq, &queue, task);
399 io_tqueue_svc_shutdown(
struct io_svc *svc)
407 int shutdown = !tq->shutdown;
410 if (shutdown && tq->submitted
419 io_tqueue_dev_cancel(dev, NULL);
423 io_tqueue_wait_func(
struct ev_task *task)
434 struct timespec now = { 0, 0 };
440 assert(tq->submitted);
442 tq->next = (
struct timespec){ 0, 0 };
444 io_tqueue_do_pop_wait(tq, &queue, NULL);
452 assert(tq->submitted);
454 tq->next = (
struct timespec){ 0, 0 };
463 wait->
task._data = NULL;
470 tq->next = wait->
value;
471 struct itimerspec value = { { 0, 0 }, tq->next };
476 tq->next = (
struct timespec){ 0, 0 };
478 io_tqueue_do_pop_wait(tq, &queue, NULL);
482 int submit = tq->submitted =
491 io_tqueue_wait_queue_post(&queue, errc);
497 io_tqueue_from_dev(
const io_dev_t *dev)
505 io_tqueue_from_svc(
const struct io_svc *svc)
540 wait->
task._data = NULL;
543 }
else if (wait->
task._data == &tq->queue) {
545 wait->
task._data = NULL;
556 wait->
task._data = NULL;
565 io_tqueue_wait_queue_post(
struct sllist *queue,
int errc)
573 io_tqueue_wait_post(wait,
errc);
int io_clock_gettime(const io_clock_t *clock, struct timespec *tp)
Obtains the current time value of the specified clock.
This header file is part of the I/O library; it contains the I/O context and service declarations.
void io_ctx_insert(io_ctx_t *ctx, struct io_svc *svc)
Registers an I/O service with an I/O context.
#define IO_SVC_INIT(vptr)
The static initializer for io_svc.
void io_ctx_remove(io_ctx_t *ctx, struct io_svc *svc)
Unregisters an I/O service with an I/O context.
This header file is part of the utilities library; it contains the native and platform-independent er...
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
@ ERRNUM_CANCELED
Operation canceled.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
This header file is part of the event library; it contains the abstract task executor interface.
size_t ev_exec_abort(ev_exec_t *exec, struct ev_task *task)
Aborts the specified task submitted to *exec, if it has not yet begun executing, or all pending tasks...
void ev_exec_post(ev_exec_t *exec, struct ev_task *task)
Submits *task to *exec for execution.
void ev_exec_on_task_fini(ev_exec_t *exec)
Undoes the effect of a previous call to ev_exec_on_task_init().
void ev_exec_on_task_init(ev_exec_t *exec)
Indicates to the specified executor that a task will be submitted for execution in the future.
void ev_promise_release(ev_promise_t *promise)
Releases a reference to a promise.
int ev_promise_set(ev_promise_t *promise, void *value)
Satiesfies a promise, if it was not aready satisfied, and stores the specified value for retrieval by...
ev_future_t * ev_promise_get_future(ev_promise_t *promise)
Returns (a reference to) a future associated with the specified promise.
ev_promise_t * ev_promise_create(size_t size, ev_promise_dtor_t *dtor)
Constructs a new promise with an optional empty shared state.
void * ev_promise_data(const ev_promise_t *promise)
Returns a pointer to the shared state of a promise.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
int io_timer_settime(io_timer_t *timer, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Arms or disarms an I/O timer.
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
struct io_timer_wait * io_timer_wait_from_task(struct ev_task *task)
Obtains a pointer to an I/O timer wait operation from a pointer to its completion task.
static size_t io_timer_abort_wait(io_timer_t *timer, struct io_timer_wait *wait)
Aborts the specified I/O timer wait operation if it is pending.
static size_t io_timer_cancel_wait(io_timer_t *timer, struct io_timer_wait *wait)
Cancels the specified I/O timer wait operation if it is pending.
io_clock_t * io_timer_get_clock(const io_timer_t *timer)
Returns a pointer to the clock used by the timer.
io_dev_t * io_timer_get_dev(const io_timer_t *timer)
Returns a pointer to the abstract I/O device representing the timer.
void io_timer_submit_wait(io_timer_t *timer, struct io_timer_wait *wait)
Submits a wait operation to an I/O timer.
#define IO_TIMER_WAIT_INIT(exec, func)
The static initializer for io_timer_wait.
This is the public header file of the utilities library.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
io_ctx_t * io_dev_get_ctx(const io_dev_t *dev)
Returns a pointer to the I/O context with which the I/O device is registered.
ev_exec_t * io_dev_get_exec(const io_dev_t *dev)
Returns a pointer to the executor used by the I/O device to execute asynchronous tasks.
struct pnode * pheap_first(const struct pheap *heap)
Returns a pointer to the first (minimum) node in a pairing heap.
void pheap_insert(struct pheap *heap, struct pnode *node)
Inserts a node into a pairing heap.
void pheap_init(struct pheap *heap, pheap_cmp_t *cmp)
Initializes a pairing heap.
void pheap_remove(struct pheap *heap, struct pnode *node)
Removes a node from a pairing heap.
int pheap_empty(const struct pheap *heap)
Returns 1 if the pairing heap is empty, and 0 if not.
void pnode_init(struct pnode *node, const void *key)
Initializes a node in a paring heap.
void sllist_init(struct sllist *list)
Initializes a singly-linked list.
void sllist_push_back(struct sllist *list, struct slnode *node)
Pushes a node to the back of a singly-linked list.
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
This is the internal header file of the I/O library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
The virtual table of an I/O service.
A wait operation suitable for use with an I/O timer.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
A wait operation suitable for use with a timer queue.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
int errc
The error number, obtained as if by get_errc(), if an error occurred or the operation was canceled.
struct timespec value
The absolute expiration time.
A node in a pairing heap.
A node in a singly-linked list.
size_t ev_task_queue_abort(struct sllist *queue)
Aborts the tasks in queue by invoking ev_exec_on_task_fini() for each of them.
struct ev_task * ev_task_from_node(struct slnode *node)
Converts a pointer to a node in a queue to the address of the task containing the node.
This header file is part of the C11 and POSIX compatibility library; it includes <threads....
int mtx_init(mtx_t *mtx, int type)
Creates a mutex object with properties indicated by type, which must have one of the four values:
int mtx_lock(mtx_t *mtx)
Blocks until it locks the mutex at mtx.
void thrd_yield(void)
Endeavors to permit other threads to run, even if the current thread would ordinarily continue to run...
@ thrd_success
Indicates that the requested operation succeeded.
int mtx_unlock(mtx_t *mtx)
Unlocks the mutex at mtx.
pthread_mutex_t mtx_t
A complete object type that holds an identifier for a mutex.
void mtx_destroy(mtx_t *mtx)
Releases any resources used by the mutex at mtx.
@ mtx_plain
A mutex type that supports neither timeout nor test and return.
io_timer_t * io_tqueue_get_timer(const io_tqueue_t *tq)
Returns a pointer to the I/O timer used by the timer queue.
void io_tqueue_destroy(io_tqueue_t *tq)
Destroys a timer queue.
size_t io_tqueue_abort_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Aborts the specified timer queue wait operation if it is pending.
size_t io_tqueue_cancel_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Cancels the specified timer queue wait operation if it is pending.
ev_future_t * io_tqueue_async_wait(io_tqueue_t *tq, ev_exec_t *exec, const struct timespec *value, struct io_tqueue_wait **pwait)
Submits an asynchronous wait operation to a timer queue and creates a future which becomes ready once...
struct io_tqueue_wait * io_tqueue_wait_from_task(struct ev_task *task)
Obtains a pointer to a timer queue wait operation from a pointer to its completion task.
void io_tqueue_submit_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Submits a wait operation to a timer queue.
io_tqueue_t * io_tqueue_create(io_timer_t *timer, ev_exec_t *exec)
Creates a new timer queue.
io_dev_t * io_tqueue_get_dev(const io_tqueue_t *tq)
Returns a pointer to the abstract I/O device representing the timer queue.
This header file is part of the I/O library; it contains the timer queue declarations.
#define IO_TQUEUE_WAIT_INIT(sec, nsec, exec, func)
The static initializer for io_tqueue_wait.
This header file is part of the utilities library; it contains the time function declarations.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.