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 
38 typedef const struct io_timer_vtbl *const io_timer_t;
39 
48  int result;
50  int errc;
51 };
52 
54 struct io_timer_wait {
59  struct ev_task task;
62 };
63 
65 #define IO_TIMER_WAIT_INIT(exec, func) \
66  { \
67  EV_TASK_INIT(exec, func), { 0, 0 } \
68  }
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 struct io_timer_vtbl {
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 
86 static inline io_ctx_t *io_timer_get_ctx(const io_timer_t *timer);
87 
89 static inline ev_exec_t *io_timer_get_exec(const io_timer_t *timer);
90 
92 static inline size_t io_timer_cancel(io_timer_t *timer, struct ev_task *task);
93 
95 static inline size_t io_timer_abort(io_timer_t *timer, struct ev_task *task);
96 
98 LELY_IO_TIMER_INLINE io_dev_t *io_timer_get_dev(const io_timer_t *timer);
99 
101 LELY_IO_TIMER_INLINE io_clock_t *io_timer_get_clock(const io_timer_t *timer);
102 
111 LELY_IO_TIMER_INLINE int io_timer_getoverrun(const io_timer_t *timer);
112 
127 LELY_IO_TIMER_INLINE int io_timer_gettime(
128  const io_timer_t *timer, struct itimerspec *value);
129 
150 LELY_IO_TIMER_INLINE int io_timer_settime(io_timer_t *timer, int flags,
151  const struct itimerspec *value, struct itimerspec *ovalue);
152 
157 LELY_IO_TIMER_INLINE void io_timer_submit_wait(
158  io_timer_t *timer, struct io_timer_wait *wait);
159 
169 static inline size_t io_timer_cancel_wait(
170  io_timer_t *timer, struct io_timer_wait *wait);
171 
180 static 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 
207 static inline io_ctx_t *
209 {
210  return io_dev_get_ctx(io_timer_get_dev(timer));
211 }
212 
213 static inline ev_exec_t *
215 {
216  return io_dev_get_exec(io_timer_get_dev(timer));
217 }
218 
219 static inline size_t
221 {
222  return io_dev_cancel(io_timer_get_dev(timer), task);
223 }
224 
225 static inline size_t
227 {
228  return io_dev_abort(io_timer_get_dev(timer), task);
229 }
230 
231 inline io_dev_t *
233 {
234  return (*timer)->get_dev(timer);
235 }
236 
237 inline io_clock_t *
239 {
240  return (*timer)->get_clock(timer);
241 }
242 
243 inline int
245 {
246  return (*timer)->getoverrun(timer);
247 }
248 
249 inline int
250 io_timer_gettime(const io_timer_t *timer, struct itimerspec *value)
251 {
252  return (*timer)->gettime(timer, value);
253 }
254 
255 inline int
256 io_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 
262 inline void
264 {
265  (*timer)->submit_wait(timer, wait);
266 }
267 
268 static inline size_t
270 {
271  return io_timer_cancel(timer, &wait->task);
272 }
273 
274 static 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_
io_timer_get_ctx
static io_ctx_t * io_timer_get_ctx(const io_timer_t *timer)
Definition: timer.h:208
io_timer_get_dev
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
io_timer_wait_result
The result of an I/O timer wait operation.
Definition: timer.h:41
ev_future
A future.
Definition: future.c:66
ev_exec_t
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
task.h
future.h
io_dev_get_exec
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
io_timer_get_exec
static ev_exec_t * io_timer_get_exec(const io_timer_t *timer)
Definition: timer.h:214
io_timer_wait_result::result
int result
The result of the wait operation: the expiration overrun count (see io_timer_getoverrun()) on success...
Definition: timer.h:48
io_dev_get_ctx
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
io_timer_get_clock
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_cancel
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
io_timer_wait::r
struct io_timer_wait_result r
The result of the wait operation.
Definition: timer.h:61
io_timer_async_wait
ev_future_t * io_timer_async_wait(io_timer_t *timer, ev_exec_t *exec, struct io_timer_wait **pwait)
Submits an asynchronous wait operation to an I/O timer and creates a future which becomes ready once ...
Definition: timer.c:39
io_timer_cancel
static size_t io_timer_cancel(io_timer_t *timer, struct ev_task *task)
Definition: timer.h:220
io_timer_wait
A wait operation suitable for use with an I/O timer.
Definition: timer.h:54
io_timer_getoverrun
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
io_timer_gettime
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
clock.h
io_timer_abort
static size_t io_timer_abort(io_timer_t *timer, struct ev_task *task)
Definition: timer.h:226
io_timer_wait_result::errc
int errc
The error number, obtained as if by get_errc(), if result is -1.
Definition: timer.h:50
io_timer_cancel_wait
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_timer_submit_wait
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
io_timer_wait::task
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition: timer.h:59
io_timer_wait_from_task
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
ev_task
An executable task.
Definition: task.h:41
io_timer_settime
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
io_timer_vtbl
Definition: timer.h:74
io_dev_t
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
Definition: dev.h:35
dev.h
io_ctx
Definition: ctx.c:38
io_timer_t
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
Definition: timer.h:38
io_dev_abort
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
io_timer_abort_wait
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
io_clock_t
const struct io_clock_vtbl *const io_clock_t
An abstract clock.
Definition: clock.h:36