Lely core libraries 2.3.4
tqueue.c File Reference

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

#include "io2.h"
#include <lely/libc/threads.h>
#include <lely/ev/exec.h>
#include <lely/io2/ctx.h>
#include <lely/io2/tqueue.h>
#include <lely/util/errnum.h>
#include <lely/util/time.h>
#include <lely/util/util.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for tqueue.c:

Go to the source code of this file.

Data Structures

struct  io_tqueue
 
struct  io_tqueue_async_wait
 

Functions

io_tqueue_tio_tqueue_create (io_timer_t *timer, ev_exec_t *exec)
 Creates a new timer queue.
 
void io_tqueue_destroy (io_tqueue_t *tq)
 Destroys a timer queue.
 
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.
 
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.
 
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.
 
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).
 
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 file is part of the I/O library; it contains the implementation of the timer queue.

See also
lely/io2/tqueue.h
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.c.

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 184 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 211 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 236 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 294 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 313 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 332 of file tqueue.c.