Lely core libraries  2.2.5
timer.h File Reference
#include <lely/ev/future.h>
#include <lely/ev/task.h>
#include <lely/io2/clock.h>
#include <lely/io2/dev.h>
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  io_timer_wait_result
 The result of an I/O timer wait operation. More...
 
struct  io_timer_wait
 A wait operation suitable for use with an I/O timer. More...
 
struct  io_timer_vtbl
 

Macros

#define IO_TIMER_WAIT_INIT(exec, func)
 The static initializer for io_timer_wait.
 

Typedefs

typedef const struct io_timer_vtbl *const io_timer_t
 An abstract timer.
 

Functions

static io_ctx_tio_timer_get_ctx (const io_timer_t *timer)
 
static ev_exec_tio_timer_get_exec (const io_timer_t *timer)
 
static size_t io_timer_cancel (io_timer_t *timer, struct ev_task *task)
 
static size_t io_timer_abort (io_timer_t *timer, struct ev_task *task)
 
io_dev_tio_timer_get_dev (const io_timer_t *timer)
 Returns a pointer to the abstract I/O device representing the timer.
 
io_clock_tio_timer_get_clock (const io_timer_t *timer)
 Returns a pointer to the clock used by the timer.
 
int io_timer_getoverrun (const io_timer_t *timer)
 Obtains the I/O timer expiration overrun count of the last successfully processed expiration. More...
 
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. More...
 
int io_timer_settime (io_timer_t *timer, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
 Arms or disarms an I/O timer. More...
 
void io_timer_submit_wait (io_timer_t *timer, struct io_timer_wait *wait)
 Submits a wait operation to an I/O timer. More...
 
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. More...
 
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. More...
 
ev_future_tio_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 the wait operation completes (or is canceled). More...
 
struct io_timer_waitio_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.
 

Detailed Description

This header file is part of the I/O library; it contains the abstract timer interface.

The timer interface is modeled after the POSIX timer_getoverrun(), timer_gettime() and timer_settime() functions.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file timer.h.

Function Documentation

◆ io_timer_get_ctx()

static io_ctx_t * io_timer_get_ctx ( const io_timer_t timer)
inlinestatic
See also
io_dev_get_ctx()

Definition at line 208 of file timer.h.

◆ io_timer_get_exec()

static ev_exec_t * io_timer_get_exec ( const io_timer_t timer)
inlinestatic
See also
io_dev_get_exec()

Definition at line 214 of file timer.h.

◆ io_timer_cancel()

static size_t io_timer_cancel ( io_timer_t timer,
struct ev_task task 
)
inlinestatic
See also
io_dev_cancel()

Definition at line 220 of file timer.h.

◆ io_timer_abort()

static size_t io_timer_abort ( io_timer_t timer,
struct ev_task task 
)
inlinestatic
See also
io_dev_abort()

Definition at line 226 of file timer.h.

◆ io_timer_getoverrun()

int io_timer_getoverrun ( const io_timer_t timer)
inline

Obtains the I/O timer expiration overrun count of the last successfully processed expiration.

When a periodic timer expires but the event is not processed before the next expiration, a timer overrun occurs.

Returns
the overrun counter, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 244 of file timer.h.

◆ io_timer_gettime()

int io_timer_gettime ( const io_timer_t timer,
struct itimerspec *  value 
)
inline

Obtains the amount of time until the specified I/O timer expires and the reload value of the timer.

Parameters
timera pointer to an I/O timer.
valuethe address at which to store the timer values. On success, the the it_value member shall contain the time interval until the next expiration, or zero if the timer is disarmed. The it_interval member shall contain the reload value last set by io_timer_settime().
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 250 of file timer.h.

◆ io_timer_settime()

int io_timer_settime ( io_timer_t timer,
int  flags,
const struct itimerspec *  value,
struct itimerspec *  ovalue 
)
inline

Arms or disarms an I/O timer.

Parameters
timera pointer to an I/O timer.
flagsif TIMER_ABSTIME is set in flags, the it_value member if *value contains the absolute time of the first expiration. If TIMER_ABSTIME is not set, the it_value member contains the time interval until the first expiration.
valuea pointer to a struct containing the period of the timer in the it_interval member and the expiration in the it_value member. If the it_value member is zero, the timer is disarmed. If the it_interval member is non-zero, a periodic (or repetitive) timer is specified. The period MAY be rounded up to the nearest multiple of the clock resolution.
ovalueif not NULL, the address at which to store the previous amount of time until the timer would have expired, together with the previous reload value, as if by atomically calling io_timer_gettime() before this function.

Definition at line 256 of file timer.h.

◆ io_timer_submit_wait()

void io_timer_submit_wait ( io_timer_t timer,
struct io_timer_wait wait 
)
inline

Submits a wait operation to an I/O timer.

The completion task is submitted for execution once the timer expires.

Definition at line 263 of file timer.h.

◆ io_timer_cancel_wait()

static size_t io_timer_cancel_wait ( io_timer_t timer,
struct io_timer_wait wait 
)
inlinestatic

Cancels the specified I/O timer wait operation if it is pending.

The completion task is submitted for execution with result = -1 and errc = errnum2c(ERRNUM_CANCELED).

Returns
1 if the operation was canceled, and 0 if it was not pending.
See also
io_dev_cancel()

Definition at line 269 of file timer.h.

◆ io_timer_abort_wait()

static size_t io_timer_abort_wait ( io_timer_t timer,
struct io_timer_wait wait 
)
inlinestatic

Aborts the specified I/O timer wait operation if it is pending.

If aborted, the completion task is not submitted for execution.

Returns
1 if the operation was aborted, and 0 if it was not pending.
See also
io_dev_abort()

Definition at line 275 of file timer.h.

◆ 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 the wait operation completes (or is canceled).

The result of the future has type io_timer_wait_result.

Parameters
timera pointer to an I/O timer.
execa pointer to the executor used to execute the completion function of the wait operation. If NULL, the default executor of the I/O timer is used.
pwaitthe address at which to store a pointer to the wait operation (can be NULL).
Returns
a pointer to a future, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 39 of file timer.c.