Pārlūkot izejas kodu

Add some macros.

master
Richard Nyberg pirms 19 gadiem
vecāks
revīzija
dc45054fe8
1 mainītis faili ar 13 papildinājumiem un 0 dzēšanām
  1. +13
    -0
      btpd/queue.h

+ 13
- 0
btpd/queue.h Parādīt failu

@@ -28,8 +28,14 @@ struct { \


#define BTPDQ_FIRST(head) ((head)->tqh_first) #define BTPDQ_FIRST(head) ((head)->tqh_first)


#define BTPDQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))

#define BTPDQ_NEXT(elm, field) ((elm)->field.tqe_next) #define BTPDQ_NEXT(elm, field) ((elm)->field.tqe_next)


#define BTPDQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))

#define BTPDQ_FOREACH(var, head, field) \ #define BTPDQ_FOREACH(var, head, field) \
for ((var) = BTPDQ_FIRST((head)); \ for ((var) = BTPDQ_FIRST((head)); \
(var); \ (var); \
@@ -51,6 +57,13 @@ struct { \
(elm)->field.tqe_prev = &BTPDQ_NEXT((listelm), field); \ (elm)->field.tqe_prev = &BTPDQ_NEXT((listelm), field); \
} while (0) } while (0)


#define BTPDQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
BTPDQ_NEXT((elm), field) = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &BTPDQ_NEXT((elm), field); \
} while (0)

#define BTPDQ_INSERT_HEAD(head, elm, field) do { \ #define BTPDQ_INSERT_HEAD(head, elm, field) do { \
if ((BTPDQ_NEXT((elm), field) = BTPDQ_FIRST((head))) != NULL) \ if ((BTPDQ_NEXT((elm), field) = BTPDQ_FIRST((head))) != NULL) \
BTPDQ_FIRST((head))->field.tqe_prev = \ BTPDQ_FIRST((head))->field.tqe_prev = \


Notiek ielāde…
Atcelt
Saglabāt