Lely core libraries 2.3.4
timer.h
Go to the documentation of this file.
1
22#ifndef LELY_IO2_INTERN_TIMER_H_
23#define LELY_IO2_INTERN_TIMER_H_
24
25#include "io2.h"
26#include <lely/ev/exec.h>
27#include <lely/io2/timer.h>
28
29#include <stdint.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35static void io_timer_wait_post(
36 struct io_timer_wait *wait, int result, int errc);
37static size_t io_timer_wait_queue_post(
38 struct sllist *queue, int result, int errc);
39
40static inline void
41io_timer_wait_post(struct io_timer_wait *wait, int result, int errc)
42{
43 wait->r.result = result;
44 wait->r.errc = errc;
45
46 ev_exec_t *exec = wait->task.exec;
47 ev_exec_post(exec, &wait->task);
49}
50
51static inline size_t
52io_timer_wait_queue_post(struct sllist *queue, int result, int errc)
53{
54 size_t n = 0;
55
56 struct slnode *node;
57 while ((node = sllist_pop_front(queue))) {
58 struct ev_task *task = ev_task_from_node(node);
60 io_timer_wait_post(wait, result, errc);
61 n += n < SIZE_MAX;
62 }
63
64 return n;
65}
66
67#ifdef __cplusplus
68}
69#endif
70
71#endif // !LELY_IO2_INTERN_TIMER_H_
This header file is part of the event library; it contains the abstract task executor interface.
void ev_exec_post(ev_exec_t *exec, struct ev_task *task)
Submits *task to *exec for execution.
Definition exec.h:124
void ev_exec_on_task_fini(ev_exec_t *exec)
Undoes the effect of a previous call to ev_exec_on_task_init().
Definition exec.h:112
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition ev.h:29
This header file is part of the I/O library; it contains the abstract timer interface.
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.
Definition timer.c:62
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
Definition sllist.h:243
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 <stdint....
An executable task.
Definition task.h:41
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition task.h:43
int errc
The error number, obtained as if by get_errc(), if result is -1.
Definition timer.h:50
int result
The result of the wait operation: the expiration overrun count (see io_timer_getoverrun()) on success...
Definition timer.h:48
A wait operation suitable for use with an I/O timer.
Definition timer.h:54
struct io_timer_wait_result r
The result of the wait operation.
Definition timer.h:61
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition timer.h:59
A singly-linked list.
Definition sllist.h:52
A node in a singly-linked list.
Definition sllist.h:40
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.
Definition task.c:32