Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[queue] avoid complaints about redefined macros

  • Loading branch information...
commit e27a57637a69af4c42f8fa8453a9fa2fc7292ad6 1 parent 2a674c6
@stewy stewy authored
Showing with 61 additions and 0 deletions.
  1. +1 −0  ChangeLog
  2. +60 −0 include/toolbox/queue.h
View
1  ChangeLog
@@ -10,6 +10,7 @@ LibU x.y.z
failures on some platforms)
- [json] fix a memory leak in the indexing interface
- [hmap] fix bad free() in hmap_clear() when user owns data
+ - [queue] avoid complaints about redefined macros
LibU 2.2.0
- [uri] fix excessively greedy match in IP-literal parser when there is no
View
60 include/toolbox/queue.h
@@ -12,34 +12,53 @@
* or at the head of the list. A list may only be traversed in the forward
* direction. */
+#ifndef LIST_HEAD
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
+#endif
+#ifndef LIST_HEAD_INITIALIZER
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
+#endif
+#ifndef LIST_ENTRY
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
+#endif
+#ifndef LIST_FIRST
#define LIST_FIRST(head) ((head)->lh_first)
+#endif
+#ifndef LIST_END
#define LIST_END(head) NULL
+#endif
+#ifndef LIST_EMPTY
#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
+#endif
+#ifndef LIST_NEXT
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+#endif
+#ifndef LIST_FOREACH
#define LIST_FOREACH(var, head, field) \
for((var) = LIST_FIRST(head); \
(var)!= LIST_END(head); \
(var) = LIST_NEXT(var, field))
+#endif
+#ifndef LIST_INIT
#define LIST_INIT(head) do { \
LIST_FIRST(head) = LIST_END(head); \
} while (0)
+#endif
+#ifndef LIST_INSERT_AFTER
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
@@ -47,28 +66,36 @@ struct { \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (0)
+#endif
+#ifndef LIST_INSERT_BEFORE
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (0)
+#endif
+#ifndef LIST_INSERT_HEAD
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (0)
+#endif
+#ifndef LIST_REMOVE
#define LIST_REMOVE(elm, field) do { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
} while (0)
+#endif
+#ifndef LIST_REPLACE
#define LIST_REPLACE(elm, elm2, field) do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
@@ -76,6 +103,7 @@ struct { \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
} while (0)
+#endif
/* A tail queue is headed by a pair of pointers, one to the head of the
@@ -86,24 +114,31 @@ struct { \
* list. A tail queue may only be traversed in the forward direction. */
/* Tail queue definitions. */
+#ifndef TAILQ_HEAD
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
}
+#endif
+#ifndef TAILQ_ENTRY
#define TAILQ_ENTRY(type) \
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}
+#endif
/* Tail queue functions. */
+#ifndef TAILQ_INIT
#define TAILQ_INIT(head) { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
}
+#endif
+#ifndef TAILQ_INSERT_HEAD
#define TAILQ_INSERT_HEAD(head, elm, field) { \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
@@ -113,14 +148,18 @@ struct { \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
}
+#endif
+#ifndef TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field) { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
}
+#endif
+#ifndef TAILQ_INSERT_AFTER
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
@@ -130,14 +169,18 @@ struct { \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
}
+#endif
+#ifndef TAILQ_INSERT_BEFORE
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (0)
+#endif
+#ifndef TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field) { \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
@@ -146,6 +189,7 @@ struct { \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
}
+#endif
/* A circle queue is headed by a pair of pointers, one to the head of the
@@ -157,24 +201,31 @@ struct { \
* complex end of list detection. */
/* Circular queue definitions. */
+#ifndef CIRCLEQ_HEAD
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
+#endif
+#ifndef CIRCLEQ_ENTRY
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
+#endif
/* Circular queue functions. */
+#ifndef CIRCLEQ_INIT
#define CIRCLEQ_INIT(head) { \
(head)->cqh_first = (void *)(head); \
(head)->cqh_last = (void *)(head); \
}
+#endif
+#ifndef CIRCLEQ_INSERT_AFTER
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
@@ -184,7 +235,9 @@ struct { \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
}
+#endif
+#ifndef CIRCLEQ_INSERT_BEFORE
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
@@ -194,7 +247,9 @@ struct { \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
}
+#endif
+#ifndef CIRCLEQ_INSERT_HEAD
#define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = (void *)(head); \
@@ -204,7 +259,9 @@ struct { \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
}
+#endif
+#ifndef CIRCLEQ_INSERT_TAIL
#define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
(elm)->field.cqe_next = (void *)(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
@@ -214,7 +271,9 @@ struct { \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
}
+#endif
+#ifndef CIRCLEQ_REMOVE
#define CIRCLEQ_REMOVE(head, elm, field) { \
if ((elm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
@@ -227,6 +286,7 @@ struct { \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
}
+#endif
#ifndef LIST_ENTRY_NULL
#define LIST_ENTRY_NULL { NULL, NULL }
Please sign in to comment.
Something went wrong with that request. Please try again.