A clone of btpd with my configuration changes.

82 lines
2.3 KiB

  1. /*
  2. * @(#)queue.h 8.5 (Berkeley) 8/20/94
  3. * $FreeBSD: src/sys/sys/queue.h,v 1.58.2.1 2005/01/31 23:26:57 imp Exp $
  4. */
  5. #ifndef BTPD_QUEUE_H
  6. #define BTPD_QUEUE_H
  7. /*
  8. * Tail queue declarations.
  9. */
  10. #define BTPDQ_HEAD(name, type) \
  11. struct name { \
  12. struct type *tqh_first; /* first element */ \
  13. struct type **tqh_last; /* addr of last next element */ \
  14. }
  15. #define BTPDQ_HEAD_INITIALIZER(head) \
  16. { NULL, &(head).tqh_first }
  17. #define BTPDQ_ENTRY(type) \
  18. struct { \
  19. struct type *tqe_next; /* next element */ \
  20. struct type **tqe_prev; /* address of previous next element */ \
  21. }
  22. #define BTPDQ_EMPTY(head) ((head)->tqh_first == NULL)
  23. #define BTPDQ_FIRST(head) ((head)->tqh_first)
  24. #define BTPDQ_NEXT(elm, field) ((elm)->field.tqe_next)
  25. #define BTPDQ_FOREACH(var, head, field) \
  26. for ((var) = BTPDQ_FIRST((head)); \
  27. (var); \
  28. (var) = BTPDQ_NEXT((var), field))
  29. #define BTPDQ_INIT(head) do { \
  30. BTPDQ_FIRST((head)) = NULL; \
  31. (head)->tqh_last = &BTPDQ_FIRST((head)); \
  32. } while (0)
  33. #define BTPDQ_INSERT_AFTER(head, listelm, elm, field) do { \
  34. if ((BTPDQ_NEXT((elm), field) = BTPDQ_NEXT((listelm), field)) != NULL)\
  35. BTPDQ_NEXT((elm), field)->field.tqe_prev = \
  36. &BTPDQ_NEXT((elm), field); \
  37. else { \
  38. (head)->tqh_last = &BTPDQ_NEXT((elm), field); \
  39. } \
  40. BTPDQ_NEXT((listelm), field) = (elm); \
  41. (elm)->field.tqe_prev = &BTPDQ_NEXT((listelm), field); \
  42. } while (0)
  43. #define BTPDQ_INSERT_HEAD(head, elm, field) do { \
  44. if ((BTPDQ_NEXT((elm), field) = BTPDQ_FIRST((head))) != NULL) \
  45. BTPDQ_FIRST((head))->field.tqe_prev = \
  46. &BTPDQ_NEXT((elm), field); \
  47. else \
  48. (head)->tqh_last = &BTPDQ_NEXT((elm), field); \
  49. BTPDQ_FIRST((head)) = (elm); \
  50. (elm)->field.tqe_prev = &BTPDQ_FIRST((head)); \
  51. } while (0)
  52. #define BTPDQ_INSERT_TAIL(head, elm, field) do { \
  53. BTPDQ_NEXT((elm), field) = NULL; \
  54. (elm)->field.tqe_prev = (head)->tqh_last; \
  55. *(head)->tqh_last = (elm); \
  56. (head)->tqh_last = &BTPDQ_NEXT((elm), field); \
  57. } while (0)
  58. #define BTPDQ_REMOVE(head, elm, field) do { \
  59. if ((BTPDQ_NEXT((elm), field)) != NULL) \
  60. BTPDQ_NEXT((elm), field)->field.tqe_prev = \
  61. (elm)->field.tqe_prev; \
  62. else { \
  63. (head)->tqh_last = (elm)->field.tqe_prev; \
  64. } \
  65. *(elm)->field.tqe_prev = BTPDQ_NEXT((elm), field); \
  66. } while (0)
  67. #endif