-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdl-intru1.h
28 lines (23 loc) · 1.04 KB
/
dl-intru1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef DL_INTRU1_H
#define DL_INTRU1_H
// see dl-intru2.* for description of the APIs and the implementation
#define DL_HEAD(_type) struct { _type *p[2]; }
#define DL_IMPL(suf, _type, _head) /* suf creates a name space for a specific type to avoid naming clash */ \
static inline void dl_push_##suf(_type *head[2], _type *p, int dir) { /* ##suf for token concatenation */ \
dir = !!dir; /* 0 or 1 */ \
p->_head.p[0] = p->_head.p[1] = 0; \
if (head[0] == 0 && head[1] == 0) head[0] = head[1] = p; \
else head[dir]->_head.p[dir] = p, p->_head.p[!dir] = head[dir], head[dir] = p; \
} \
static inline _type *dl_pop_##suf(_type *head[2], int dir) { \
_type *p; \
dir = !!dir; \
if (head[0] == 0 && head[1] == 0) return 0; \
else if (head[0] == head[1]) p = head[0], head[0] = head[1] = 0; \
else p = head[dir], head[dir] = p->_head.p[!dir], head[dir]->_head.p[dir] = 0; \
return p; \
}
// more convenient macro APIs
#define dl_push(suf, head, p, dir) dl_push_##suf(head, p, dir)
#define dl_pop(suf, head, dir) dl_pop_##suf(head, dir)
#endif