Lely core libraries  2.2.5
tqueue.h File Reference
#include <lely/io2/timer.h>
#include <lely/util/pheap.h>
Include dependency graph for tqueue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  io_tqueue_wait
 A wait operation suitable for use with a timer queue. More...
 

Macros

#define IO_TQUEUE_WAIT_INIT(sec, nsec, exec, func)
 The static initializer for io_tqueue_wait.
 

Typedefs

typedef struct io_tqueue io_tqueue_t
 A timer queue.
 

Functions

io_tqueue_tio_tqueue_create (io_timer_t *timer, ev_exec_t *exec)
 Creates a new timer queue. More...
 
void io_tqueue_destroy (io_tqueue_t *tq)
 Destroys a timer queue. More...
 
io_dev_tio_tqueue_get_dev (const io_tqueue_t *tq)
 Returns a pointer to the abstract I/O device representing the timer queue.
 
io_timer_tio_tqueue_get_timer (const io_tqueue_t *tq)
 Returns a pointer to the I/O timer used by the timer queue.
 
void io_tqueue_submit_wait (io_tqueue_t *tq, struct io_tqueue_wait *wait)
 Submits a wait operation to a timer queue. More...
 
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. More...
 
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. More...
 
ev_future_tio_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 the wait operation completes (or is canceled). More...
 
struct io_tqueue_waitio_tqueue_wait_from_task (struct ev_task *task)
 Obtains a pointer to a timer queue wait operation from a pointer to its completion task.
 

Detailed Description

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

A timer queue allows multiple non-periodic wait operations with different expiration times to use the same I/O timer. This is much more efficient than creating a separate I/O timer for each concurrent wait.

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 tqueue.h.

Function Documentation

◆ io_tqueue_create()

io_tqueue_t* io_tqueue_create ( io_timer_t timer,
ev_exec_t exec 
)

Creates a new timer queue.

Parameters
timera pointer to the I/O timer to be used for the queue. During the lifetime of the timer queue, io_timer_settime() MUST NOT be invoked.
execa pointer to the executor used to execute asynchronous tasks. If exec is NULL, the executor of the I/O timer is used.
Returns
a pointer to a new timer queue, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 179 of file tqueue.c.

◆ io_tqueue_destroy()

void io_tqueue_destroy ( io_tqueue_t tq)

Destroys a timer queue.

See also
io_tqueue_create()

Definition at line 206 of file tqueue.c.

◆ io_tqueue_submit_wait()

void io_tqueue_submit_wait ( io_tqueue_t tq,
struct io_tqueue_wait wait 
)

Submits a wait operation to a timer queue.

The completion task is submitted for execution once the timeout specified in the value member of the wait operation expires.

Definition at line 231 of file tqueue.c.

◆ io_tqueue_cancel_wait()

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.

The completion task is submitted for execution with 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 288 of file tqueue.c.

◆ io_tqueue_abort_wait()

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.

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 307 of file tqueue.c.

◆ io_tqueue_async_wait()

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

The result of the future is an int containing the error number.

Parameters
tqa pointer to a timer queue.
execa pointer to the executor used to execute the completion function of the wait operation. If NULL, the default executor of the timer queue is used.
valuea pointer to the absolute expiration time.
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 326 of file tqueue.c.