Lely core libraries 2.3.4
timer.h
Go to the documentation of this file.
1
25#ifndef LELY_IO2_TIMER_H_
26#define LELY_IO2_TIMER_H_
27
28#include <lely/ev/future.h>
29#include <lely/ev/task.h>
30#include <lely/io2/clock.h>
31#include <lely/io2/dev.h>
32
33#ifndef LELY_IO_TIMER_INLINE
34#define LELY_IO_TIMER_INLINE static inline
35#endif
36
38typedef const struct io_timer_vtbl *const io_timer_t;
39
48 int result;
50 int errc;
51};
52
63
65#define IO_TIMER_WAIT_INIT(exec, func) \
66 { \
67 EV_TASK_INIT(exec, func), { 0, 0 } \
68 }
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
75 io_dev_t *(*get_dev)(const io_timer_t *timer);
76 io_clock_t *(*get_clock)(const io_timer_t *timer);
77 int (*getoverrun)(const io_timer_t *timer);
78 int (*gettime)(const io_timer_t *timer, struct itimerspec *value);
79 int (*settime)(io_timer_t *timer, int flags,
80 const struct itimerspec *value,
81 struct itimerspec *ovalue);
82 void (*submit_wait)(io_timer_t *timer, struct io_timer_wait *wait);
83};
84
86static inline io_ctx_t *io_timer_get_ctx(const io_timer_t *timer);
87
89static inline ev_exec_t *io_timer_get_exec(const io_timer_t *timer);
90
92static inline size_t io_timer_cancel(io_timer_t *timer, struct ev_task *task);
93
95static inline size_t io_timer_abort(io_timer_t *timer, struct ev_task *task);
96
98LELY_IO_TIMER_INLINE io_dev_t *io_timer_get_dev(const io_timer_t *timer);
99
101LELY_IO_TIMER_INLINE io_clock_t *io_timer_get_clock(const io_timer_t *timer);
102
111LELY_IO_TIMER_INLINE int io_timer_getoverrun(const io_timer_t *timer);
112
127LELY_IO_TIMER_INLINE int io_timer_gettime(
128 const io_timer_t *timer, struct itimerspec *value);
129
150LELY_IO_TIMER_INLINE int io_timer_settime(io_timer_t *timer, int flags,
151 const struct itimerspec *value, struct itimerspec *ovalue);
152
157LELY_IO_TIMER_INLINE void io_timer_submit_wait(
158 io_timer_t *timer, struct io_timer_wait *wait);
159
169static inline size_t io_timer_cancel_wait(
170 io_timer_t *timer, struct io_timer_wait *wait);
171
180static inline size_t io_timer_abort_wait(
181 io_timer_t *timer, struct io_timer_wait *wait);
182
199 struct io_timer_wait **pwait);
200
206
207static inline io_ctx_t *
209{
210 return io_dev_get_ctx(io_timer_get_dev(timer));
211}
212
213static inline ev_exec_t *
215{
216 return io_dev_get_exec(io_timer_get_dev(timer));
217}
218
219static inline size_t
221{
222 return io_dev_cancel(io_timer_get_dev(timer), task);
223}
224
225static inline size_t
227{
228 return io_dev_abort(io_timer_get_dev(timer), task);
229}
230
231inline io_dev_t *
233{
234 return (*timer)->get_dev(timer);
235}
236
237inline io_clock_t *
239{
240 return (*timer)->get_clock(timer);
241}
242
243inline int
245{
246 return (*timer)->getoverrun(timer);
247}
248
249inline int
250io_timer_gettime(const io_timer_t *timer, struct itimerspec *value)
251{
252 return (*timer)->gettime(timer, value);
253}
254
255inline int
256io_timer_settime(io_timer_t *timer, int flags, const struct itimerspec *value,
257 struct itimerspec *ovalue)
258{
259 return (*timer)->settime(timer, flags, value, ovalue);
260}
261
262inline void
264{
265 (*timer)->submit_wait(timer, wait);
266}
267
268static inline size_t
270{
271 return io_timer_cancel(timer, &wait->task);
272}
273
274static inline size_t
276{
277 return io_timer_abort(timer, &wait->task);
278}
279
280#ifdef __cplusplus
281}
282#endif
283
284#endif // !LELY_IO2_TIMER_H_
This header file is part of the I/O library; it contains the abstract clock interface.
const struct io_clock_vtbl *const io_clock_t
An abstract clock.
Definition clock.h:36
This header file is part of the event library; it contains the futures and promises declarations.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition ev.h:29
int io_timer_settime(io_timer_t *timer, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Arms or disarms an I/O timer.
Definition timer.h:256
static ev_exec_t * io_timer_get_exec(const io_timer_t *timer)
Definition timer.h:214
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
Definition timer.h:38
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.
Definition timer.h:275
static size_t io_timer_cancel(io_timer_t *timer, struct ev_task *task)
Definition timer.h:220
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.
Definition timer.h:269
io_clock_t * io_timer_get_clock(const io_timer_t *timer)
Returns a pointer to the clock used by the timer.
Definition timer.h:238
io_dev_t * io_timer_get_dev(const io_timer_t *timer)
Returns a pointer to the abstract I/O device representing the timer.
Definition timer.h:232
void io_timer_submit_wait(io_timer_t *timer, struct io_timer_wait *wait)
Submits a wait operation to an I/O timer.
Definition timer.h:263
static size_t io_timer_abort(io_timer_t *timer, struct ev_task *task)
Definition timer.h:226
static io_ctx_t * io_timer_get_ctx(const io_timer_t *timer)
Definition timer.h:208
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
int io_timer_getoverrun(const io_timer_t *timer)
Obtains the I/O timer expiration overrun count of the last successfully processed expiration.
Definition timer.h:244
int io_timer_gettime(const io_timer_t *timer, struct itimerspec *value)
Obtains the amount of time until the specified I/O timer expires and the reload value of the timer.
Definition timer.h:250
This header file is part of the I/O library; it contains the abstract I/O device interface.
size_t io_dev_abort(io_dev_t *dev, struct ev_task *task)
Aborts the asynchronous operation submitted to *dev, if its task has not yet been submitted to its ex...
Definition dev.h:98
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
Definition dev.h:35
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.
Definition dev.h:80
size_t io_dev_cancel(io_dev_t *dev, struct ev_task *task)
Cancels the asynchronous operation submitted to *dev, if its task has not yet been submitted to its e...
Definition dev.h:92
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.
Definition dev.h:86
A future.
Definition future.c:66
An executable task.
Definition task.h:41
Definition ctx.c:38
The result of an I/O timer wait operation.
Definition timer.h:41
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 struct specifying an interval and initial value for a timer.
Definition time.h:100
This header file is part of the event library; it contains the task declarations.