Commit 65949659 authored by ROOL's avatar ROOL 🤖
Browse files

Updates to queue.h macros

Detail:
  Add safe _FOREACH iterators to the rest of the queue.h types (from FreeBSD revision 118904).
  Retire CIRCLEQ. Use TAILQ instead, it provides the same functionality (from FreeBSD revision 70469).

Version 5.63. Tagged as 'TCPIPLibs-5_63'
parent 41cbe333
/* (5.62)
/* (5.63)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 5.62
#define Module_MajorVersion_CMHG 5.63
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 23 Jun 2017
#define Module_Date_CMHG 13 Jan 2018
#define Module_MajorVersion "5.62"
#define Module_Version 562
#define Module_MajorVersion "5.63"
#define Module_Version 563
#define Module_MinorVersion ""
#define Module_Date "23 Jun 2017"
#define Module_Date "13 Jan 2018"
#define Module_ApplicationDate "23-Jun-17"
#define Module_ApplicationDate "13-Jan-18"
#define Module_ComponentName "TCPIPLibs"
#define Module_ComponentPath "mixed/RiscOS/Sources/Lib/TCPIPLibs"
#define Module_FullVersion "5.62"
#define Module_HelpVersion "5.62 (23 Jun 2017)"
#define Module_LibraryVersionInfo "5:62"
#define Module_FullVersion "5.63"
#define Module_HelpVersion "5.63 (13 Jan 2018)"
#define Module_LibraryVersionInfo "5:63"
......@@ -31,15 +31,15 @@
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
* FreeBSD: 51955 1999/10/05 20:35:32
* FreeBSD: 118904 2003/08/14 14:49:26
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* slingly-linked tail queues, lists, tail queues, and circular queues.
* This file defines four types of data structures: singly-linked lists,
* singly-linked tail queues, lists and tail queues.
*
* A singly-linked list is headed by a single forward pointer. The elements
* are singly linked for minimum space and pointer manipulation overhead at
......@@ -77,40 +77,34 @@
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may only be traversed in the forward direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
* the list. A tail queue may be traversed in either direction.
*
* For details on the use of these macros, see the queue(3) manual page.
*
*
* SLIST LIST STAILQ TAILQ CIRCLEQ
* _HEAD + + + + +
* _ENTRY + + + + +
* _INIT + + + + +
* _EMPTY + + + + +
* _FIRST + + + + +
* _NEXT + + + + +
* _PREV - - - + +
* _LAST - - + + +
* _FOREACH + + + + +
* _INSERT_HEAD + + + + +
* _INSERT_BEFORE - + - + +
* _INSERT_AFTER + + + + +
* _INSERT_TAIL - - + + +
* _REMOVE_HEAD + - + - -
* _REMOVE + + + + +
* SLIST LIST STAILQ TAILQ
* _HEAD + + + +
* _HEAD_INITIALIZER + + + +
* _ENTRY + + + +
* _INIT + + + +
* _EMPTY + + + +
* _FIRST + + + +
* _NEXT + + + +
* _PREV - - - +
* _LAST - - + +
* _FOREACH + + + +
* _FOREACH_SAFE + + + +
* _INSERT_HEAD + + + +
* _INSERT_BEFORE - + - +
* _INSERT_AFTER + + + +
* _INSERT_TAIL - - + +
* _REMOVE_HEAD + - + -
* _REMOVE + + + +
*
*/
/*
* Singly-linked List definitions.
* Singly-linked List declarations.
*/
#define SLIST_HEAD(name, type) \
struct name { \
......@@ -135,6 +129,11 @@ struct { \
#define SLIST_FOREACH(var, head, field) \
for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST((head)); \
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
(var) = (tvar))
#define SLIST_INIT(head) { \
(head)->slh_first = NULL; \
}
......@@ -169,7 +168,7 @@ struct { \
} while (0)
/*
* Singly-linked Tail queue definitions.
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
......@@ -201,6 +200,12 @@ struct { \
#define STAILQ_FOREACH(var, head, field) \
for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next)
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = STAILQ_FIRST((head)); \
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
(head)->stqh_last = &(elm)->field.stqe_next; \
......@@ -265,7 +270,7 @@ struct { \
#define SIMPLEQ_REMOVE STAILQ_REMOVE
/*
* List definitions.
* List declarations.
*/
#define LIST_HEAD(name, type) \
struct name { \
......@@ -292,6 +297,11 @@ struct { \
#define LIST_FOREACH(var, head, field) \
for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next)
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#define LIST_INIT(head) do { \
(head)->lh_first = NULL; \
} while (0)
......@@ -328,7 +338,7 @@ struct { \
} while (0)
/*
* Tail queue definitions.
* Tail queue declarations.
*/
#define TAILQ_HEAD(name, type) \
struct name { \
......@@ -353,6 +363,11 @@ struct { \
#define TAILQ_FOREACH(var, head, field) \
for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_LAST(head, headname) \
......@@ -411,98 +426,8 @@ struct { \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (0)
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue functions.
*/
#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_FOREACH(var, head, field) \
for((var) = (head)->cqh_first; \
(var) != (void *)(head); \
(var) = (var)->field.cqe_next)
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = (void *)(head); \
(head)->cqh_last = (void *)(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = (void *)(head); \
if ((head)->cqh_last == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.cqe_next = (void *)(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
} while (0)
#ifdef KERNEL
#ifdef _KERNEL
/*
* XXX insque() and remque() are an old way of handling certain queues.
......@@ -519,7 +444,8 @@ struct quehead {
static __inline void
insque(void *a, void *b)
{
struct quehead *element = a, *head = b;
struct quehead *element = (struct quehead *)a,
*head = (struct quehead *)b;
element->qh_link = head->qh_link;
element->qh_rlink = head;
......@@ -530,7 +456,7 @@ insque(void *a, void *b)
static __inline void
remque(void *a)
{
struct quehead *element = a;
struct quehead *element = (struct quehead *)a;
element->qh_link->qh_rlink = element->qh_rlink;
element->qh_rlink->qh_link = element->qh_link;
......@@ -544,6 +470,6 @@ void remque(void *a);
#endif /* __GNUC__ */
#endif /* KERNEL */
#endif /* _KERNEL */
#endif /* !_SYS_QUEUE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment