2020-10-23 14:57:27 +00:00
|
|
|
.\" Copyright (c) 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\" and Copyright (c) 2020 by Alejandro Colomar <colomar.6.4.3@gmail.com>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
|
|
|
.\"
|
|
|
|
.TH CIRCLEQ 3 2020-10-21 "GNU" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
2020-10-23 14:57:28 +00:00
|
|
|
.Nm CIRCLEQ_EMPTY ,
|
|
|
|
.Nm CIRCLEQ_ENTRY ,
|
|
|
|
.Nm CIRCLEQ_FIRST ,
|
|
|
|
.Nm CIRCLEQ_FOREACH ,
|
|
|
|
.Nm CIRCLEQ_FOREACH_REVERSE ,
|
|
|
|
.Nm CIRCLEQ_HEAD ,
|
|
|
|
.Nm CIRCLEQ_HEAD_INITIALIZER ,
|
|
|
|
.Nm CIRCLEQ_INIT ,
|
|
|
|
.Nm CIRCLEQ_INSERT_AFTER ,
|
|
|
|
.Nm CIRCLEQ_INSERT_BEFORE ,
|
|
|
|
.Nm CIRCLEQ_INSERT_HEAD ,
|
|
|
|
.Nm CIRCLEQ_INSERT_TAIL ,
|
|
|
|
.Nm CIRCLEQ_LAST ,
|
|
|
|
.Nm CIRCLEQ_LOOP_NEXT ,
|
|
|
|
.Nm CIRCLEQ_LOOP_PREV ,
|
|
|
|
.Nm CIRCLEQ_NEXT ,
|
|
|
|
.Nm CIRCLEQ_PREV ,
|
|
|
|
.Nm CIRCLEQ_REMOVE
|
2020-10-23 14:57:27 +00:00
|
|
|
.SH SYNOPSIS
|
2020-10-23 14:57:29 +00:00
|
|
|
.Fn CIRCLEQ_EMPTY "CIRCLEQ_HEAD *head"
|
|
|
|
.Fn CIRCLEQ_ENTRY "TYPE"
|
|
|
|
.Fn CIRCLEQ_FIRST "CIRCLEQ_HEAD *head"
|
|
|
|
.Fn CIRCLEQ_FOREACH "TYPE *var" "CIRCLEQ_HEAD *head" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_FOREACH_REVERSE "TYPE *var" "CIRCLEQ_HEAD *head" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_HEAD "HEADNAME" "TYPE"
|
|
|
|
.Fn CIRCLEQ_HEAD_INITIALIZER "CIRCLEQ_HEAD head"
|
|
|
|
.Fn CIRCLEQ_INIT "CIRCLEQ_HEAD *head"
|
|
|
|
.Fn CIRCLEQ_INSERT_AFTER "CIRCLEQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_INSERT_BEFORE "CIRCLEQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_INSERT_HEAD "CIRCLEQ_HEAD *head" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_INSERT_TAIL "CIRCLEQ_HEAD *head" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_LAST "CIRCLEQ_HEAD *head"
|
|
|
|
.Fn CIRCLEQ_LOOP_NEXT "CIRCLEQ_HEAD *head" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_LOOP_PREV "CIRCLEQ_HEAD *head" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_NEXT "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_PREV "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
|
|
|
.Fn CIRCLEQ_REMOVE "CIRCLEQ_HEAD *head" "TYPE *elm" "CIRCLEQ_ENTRY NAME"
|
2020-10-23 14:57:27 +00:00
|
|
|
.SH DESCRIPTION
|
2020-10-23 14:57:30 +00:00
|
|
|
.Ss Circular queues
|
|
|
|
A circular queue is headed by a structure defined by the
|
|
|
|
.Nm CIRCLEQ_HEAD
|
|
|
|
macro.
|
|
|
|
This structure contains a pair of pointers,
|
|
|
|
one to the first element in the circular queue and the other to
|
|
|
|
the last element in the circular queue.
|
|
|
|
The elements are doubly linked so that an arbitrary element can be
|
|
|
|
removed without traversing the circular queue.
|
|
|
|
New elements can be added to the circular queue after an existing element,
|
|
|
|
before an existing element, at the head of the circular queue,
|
|
|
|
or at the end of the circular queue.
|
|
|
|
A
|
|
|
|
.Fa CIRCLEQ_HEAD
|
|
|
|
structure is declared as follows:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
CIRCLEQ_HEAD(HEADNAME, TYPE) head;
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
where
|
|
|
|
.Li HEADNAME
|
|
|
|
is the name of the structure to be defined, and
|
|
|
|
.Li TYPE
|
|
|
|
is the type of the elements to be linked into the circular queue.
|
|
|
|
A pointer to the head of the circular queue can later be declared as:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
struct HEADNAME *headp;
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
(The names
|
|
|
|
.Li head
|
|
|
|
and
|
|
|
|
.Li headp
|
|
|
|
are user selectable.)
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_HEAD_INITIALIZER
|
|
|
|
evaluates to an initializer for the circular queue
|
|
|
|
.Fa head .
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_EMPTY
|
|
|
|
evaluates to true if there are no items on the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_ENTRY
|
|
|
|
declares a structure that connects the elements in
|
|
|
|
the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_FIRST
|
|
|
|
returns the first item on the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_FOREACH
|
|
|
|
traverses the circular queue referenced by
|
|
|
|
.Fa head
|
|
|
|
in the forward direction, assigning each element in turn to
|
|
|
|
.Fa var .
|
|
|
|
.Fa var
|
|
|
|
is set to
|
|
|
|
.Fa &head
|
|
|
|
if the loop completes normally, or if there were no elements.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_FOREACH_REVERSE
|
|
|
|
traverses the circular queue referenced by
|
|
|
|
.Fa head
|
|
|
|
in the reverse direction, assigning each element in turn to
|
|
|
|
.Fa var .
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_INIT
|
|
|
|
initializes the circular queue referenced by
|
|
|
|
.Fa head .
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_INSERT_HEAD
|
|
|
|
inserts the new element
|
|
|
|
.Fa elm
|
|
|
|
at the head of the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_INSERT_TAIL
|
|
|
|
inserts the new element
|
|
|
|
.Fa elm
|
|
|
|
at the end of the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_INSERT_AFTER
|
|
|
|
inserts the new element
|
|
|
|
.Fa elm
|
|
|
|
after the element
|
|
|
|
.Fa listelm .
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_INSERT_BEFORE
|
|
|
|
inserts the new element
|
|
|
|
.Fa elm
|
|
|
|
before the element
|
|
|
|
.Fa listelm .
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_LAST
|
|
|
|
returns the last item on the circular queue.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_NEXT
|
|
|
|
returns the next item on the circular queue, or
|
|
|
|
.Fa &head
|
|
|
|
if this item is the last one.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_PREV
|
|
|
|
returns the previous item on the circular queue, or
|
|
|
|
.Fa &head
|
|
|
|
if this item is the first one.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_LOOP_NEXT
|
|
|
|
returns the next item on the circular queue.
|
|
|
|
If
|
|
|
|
.Fa elm
|
|
|
|
is the last element on the circular queue, the first element is returned.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_LOOP_PREV
|
|
|
|
returns the previous item on the circular queue.
|
|
|
|
If
|
|
|
|
.Fa elm
|
|
|
|
is the first element on the circular queue, the last element is returned.
|
|
|
|
.Pp
|
|
|
|
The macro
|
|
|
|
.Nm CIRCLEQ_REMOVE
|
|
|
|
removes the element
|
|
|
|
.Fa elm
|
|
|
|
from the circular queue.
|
2020-10-23 14:57:27 +00:00
|
|
|
.SH RETURN VALUE
|
|
|
|
.SH CONFORMING TO
|
|
|
|
.SH BUGS
|
|
|
|
.SH EXAMPLES
|
|
|
|
.SH SEE ALSO
|