| 1 |
/* |
| 2 |
* Copyright (C) by Argonne National Laboratory |
| 3 |
* See COPYRIGHT in top-level directory |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef TCP_QUEUE_H_INCLUDED |
| 7 |
#define TCP_QUEUE_H_INCLUDED |
| 8 |
|
| 9 |
/* Generic queue macros -- "next_field" should be set to the name of |
| 10 |
the next pointer field in the element (e.g., "ch.tcp_sendq_next") */ |
| 11 |
|
| 12 |
#define PRINT_QUEUE(qp, next_field) do { \ |
| 13 |
} while (0) |
| 14 |
|
| 15 |
|
| 16 |
#define GENERIC_Q_EMPTY(q) ((q).head == NULL) |
| 17 |
|
| 18 |
#define GENERIC_Q_HEAD(q) ((q).head) |
| 19 |
|
| 20 |
#define GENERIC_Q_ENQUEUE_EMPTY(qp, ep, next_field) do { \ |
| 21 |
MPIR_Assert (GENERIC_Q_EMPTY (*(qp))); \ |
| 22 |
(qp)->head = (qp)->tail = ep; \ |
| 23 |
(ep)->next_field = NULL; \ |
| 24 |
PRINT_QUEUE (qp, next_field); \ |
| 25 |
} while (0) |
| 26 |
|
| 27 |
#define GENERIC_Q_ENQUEUE(qp, ep, next_field) do { \ |
| 28 |
if (GENERIC_Q_EMPTY (*(qp))) \ |
| 29 |
GENERIC_Q_ENQUEUE_EMPTY (qp, ep, next_field); \ |
| 30 |
else \ |
| 31 |
{ \ |
| 32 |
(qp)->tail->next_field = (qp)->tail = ep; \ |
| 33 |
(ep)->next_field = NULL; \ |
| 34 |
} \ |
| 35 |
PRINT_QUEUE (qp, next_field); \ |
| 36 |
} while (0) |
| 37 |
|
| 38 |
/* the _MULTIPLE routines assume that ep0 is the head and ep1 is the |
| 39 |
tail of a linked list of elements. The list is inserted on the end |
| 40 |
of the queue. */ |
| 41 |
#define GENERIC_Q_ENQUEUE_EMPTY_MULTIPLE(qp, ep0, ep1, next_field) do { \ |
| 42 |
MPIR_Assert (GENERIC_Q_EMPTY (*(qp))); \ |
| 43 |
(qp)->head = ep0; \ |
| 44 |
(qp)->tail = ep1; \ |
| 45 |
(ep1)->next_field = NULL; \ |
| 46 |
} while (0) |
| 47 |
|
| 48 |
#define GENERIC_Q_ENQUEUE_MULTIPLE(qp, ep0, ep1, next_field) do { \ |
| 49 |
if (GENERIC_Q_EMPTY (*(qp))) \ |
| 50 |
GENERIC_Q_ENQUEUE_EMPTY_MULTIPLE (qp, ep0, ep1, next_field); \ |
| 51 |
else \ |
| 52 |
{ \ |
| 53 |
(qp)->tail->next_field = ep0; \ |
| 54 |
(qp)->tail = ep1; \ |
| 55 |
(ep1)->next_field = NULL; \ |
| 56 |
} \ |
| 57 |
} while (0) |
| 58 |
|
| 59 |
|
| 60 |
#define GENERIC_Q_DEQUEUE(qp, epp, next_field) do { \ |
| 61 |
MPIR_Assert (!GENERIC_Q_EMPTY (*(qp))); \ |
| 62 |
*(epp) = (qp)->head; \ |
| 63 |
(qp)->head = (*(epp))->next_field; \ |
| 64 |
if ((qp)->head == NULL) \ |
| 65 |
(qp)->tail = NULL; \ |
| 66 |
} while (0) |
| 67 |
|
| 68 |
/* remove the elements from the top of the queue starting with ep0 through ep1 */ |
| 69 |
#define GENERIC_Q_REMOVE_ELEMENTS(qp, ep0, ep1, next_field) do { \ |
| 70 |
MPIR_Assert (GENERIC_Q_HEAD (*(qp)) == (ep0)); \ |
| 71 |
(qp)->head = (ep1)->next_field; \ |
| 72 |
if ((qp)->head == NULL) \ |
| 73 |
(qp)->tail = NULL; \ |
| 74 |
} while (0) |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
/* Generic list macros */ |
| 79 |
#define GENERIC_L_EMPTY(q) ((q).head == NULL) |
| 80 |
|
| 81 |
#define GENERIC_L_HEAD(q) ((q).head) |
| 82 |
|
| 83 |
#define GENERIC_L_ADD_EMPTY(qp, ep, next_field, prev_field) do { \ |
| 84 |
MPIR_Assert (GENERIC_L_EMPTY (*(qp))); \ |
| 85 |
(qp)->head = ep; \ |
| 86 |
(ep)->next_field = (ep)->prev_field = NULL; \ |
| 87 |
} while (0) |
| 88 |
|
| 89 |
#define GENERIC_L_ADD(qp, ep, next_field, prev_field) do { \ |
| 90 |
if (GENERIC_L_EMPTY (*(qp))) \ |
| 91 |
GENERIC_L_ADD_EMPTY (qp, ep, next_field, prev_field); \ |
| 92 |
else \ |
| 93 |
{ \ |
| 94 |
(ep)->prev_field = NULL; \ |
| 95 |
(ep)->next_field = (qp)->head; \ |
| 96 |
(qp)->head->prev_field = ep; \ |
| 97 |
(qp)->head = ep; \ |
| 98 |
} \ |
| 99 |
} while (0) |
| 100 |
|
| 101 |
#define GENERIC_L_REMOVE(qp, ep, next_field, prev_field) do { \ |
| 102 |
MPIR_Assert (!GENERIC_L_EMPTY (*(qp))); \ |
| 103 |
if ((ep)->prev_field) \ |
| 104 |
((ep)->prev_field)->next_field = (ep)->next_field; \ |
| 105 |
else \ |
| 106 |
(qp)->head = (ep)->next_field; \ |
| 107 |
if ((ep)->next_field) \ |
| 108 |
((ep)->next_field)->prev_field = (ep)->prev_field; \ |
| 109 |
} while (0) |
| 110 |
|
| 111 |
|
| 112 |
/* Generic stack macros */ |
| 113 |
#define GENERIC_S_EMPTY(s) ((s).top == NULL) |
| 114 |
|
| 115 |
#define GENERIC_S_TOP(s) ((s).top) |
| 116 |
|
| 117 |
#define GENERIC_S_PUSH(sp, ep, next_field) do { \ |
| 118 |
(ep)->next_field = (sp)->top; \ |
| 119 |
(sp)->top = ep; \ |
| 120 |
} while (0) |
| 121 |
|
| 122 |
/* PUSH_MULTIPLE pushes a linked list of elements onto the stack. It |
| 123 |
assumes that ep0 is the head of the linked list and ep1 is at the tail */ |
| 124 |
#define GENERIC_S_PUSH_MULTIPLE(sp, ep0, ep1, next_field) do { \ |
| 125 |
(ep1)->next_field = (sp)->top; \ |
| 126 |
(sp)->top = ep0; \ |
| 127 |
} while (0) |
| 128 |
|
| 129 |
#define GENERIC_S_POP(sp, ep, next_field) do { \ |
| 130 |
*(ep) = (sp)->top; \ |
| 131 |
(sp)->top = (*(ep))->next_field; \ |
| 132 |
} while (0) |
| 133 |
#endif /* TCP_QUEUE_H_INCLUDED */ |