00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include<stddef.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #define offsetofnew(TYPE, MEMBER) (((size_t) &((TYPE *)4)->MEMBER) - 4 )
00035
00036 #define VIRTORG(p, st, lk) ( \
00037 (st *) ( \
00038 ((char *) (&p)) - offsetofnew(st, lk) \
00039 ) )
00040
00041
00042 #define DQUEUE(somestruct) \
00043 struct { \
00044 somestruct *linkf; \
00045 somestruct *linkb; \
00046 }
00047
00048
00049 #define DQUEUE_INIT(head, st, link) \
00050 (head).linkb = (head).linkf = VIRTORG(head, st, link);
00051
00052
00053 #define DQUEUE_ADD(new, node, link) \
00054 do \
00055 { \
00056 (new)->link.linkf = (node)->link.linkf; \
00057 (new)->link.linkb = (node); \
00058 (node)->link.linkf->link.linkb = (new); \
00059 (node)->link.linkf = (new); \
00060 } while(0)
00061
00062
00063 #define DQUEUE_RMV(node, link) \
00064 do \
00065 { \
00066 (node)->link.linkb->link.linkf = (node)->link.linkf; \
00067 (node)->link.linkf->link.linkb = (node)->link.linkb; \
00068 } while(0)
00069
00070
00071 #define DQUEUE_TEST(head, st, link) \
00072 ((head).linkf == VIRTORG(head, st, link))
00073
00074
00075
00076
00077 #define SQUEUE_HEAD(somestruct) \
00078 struct \
00079 { \
00080 somestruct *lifot; \
00081 somestruct *lifob; \
00082 }
00083
00084 #define SQUEUE_INIT(head, st, link) \
00085 (head).lifot = NULL; \
00086 (head).lifob = VIRTORG(head, st, link)
00087
00088
00089 #define SQUEUE_ADD(new, head, link) \
00090 (new)->link = NULL; \
00091 (head).lifob->link = (new); \
00092 (head).lifob = (new);
00093
00094
00095 #define SQUEUE_TEST(head) \
00096 (head).lifot
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 #define SQUEUE_RMV(result, head, st, link) \
00107 result = (head).lifot; \
00108 (head).lifot = result->link; \
00109 if (((head).lifot) == NULL) \
00110 { \
00111 (head).lifob = VIRTORG(head, st, link); \
00112 }