67
67
#ifndef _DBLLNKLST_H_
68
68
#define _DBLLNKLST_H_
70
#include "vm_basic_types.h"
72
70
#define INCLUDE_ALLOW_MODULE
73
71
#define INCLUDE_ALLOW_USERLEVEL
74
72
#include "includeCheck.h"
74
#include "vm_basic_types.h"
77
77
#define DblLnkLst_OffsetOf(type, field) ((intptr_t)&((type *)0)->field)
79
79
#define DblLnkLst_Container(addr, type, field) \
80
((type *)((char *)addr - DblLnkLst_OffsetOf(type, field)))
80
((type *)((char *)(addr) - DblLnkLst_OffsetOf(type, field)))
82
82
#define DblLnkLst_ForEach(curr, head) \
83
83
for (curr = (head)->next; curr != (head); curr = (curr)->next)
97
/* Functions for both circular and anchored lists. --hpreg */
99
void DblLnkLst_Init(DblLnkLst_Links *l);
100
void DblLnkLst_Link(DblLnkLst_Links *l1, DblLnkLst_Links *l2);
101
void DblLnkLst_Unlink(DblLnkLst_Links *l1, DblLnkLst_Links *l2);
102
void DblLnkLst_Unlink1(DblLnkLst_Links *l);
103
Bool DblLnkLst_IsLinked(DblLnkLst_Links const *l);
105
/* Functions specific to anchored lists. --hpreg */
107
void DblLnkLst_LinkFirst(DblLnkLst_Links *head, DblLnkLst_Links *l);
108
void DblLnkLst_LinkLast(DblLnkLst_Links *head, DblLnkLst_Links *l);
100
* DblLnkLst_LinkFirst and DblLnkLst_LinkLast are specific
101
* to anchored lists. The rest are for both circular and
107
*----------------------------------------------------------------------
111
* Initialize a member of a doubly linked list
119
*----------------------------------------------------------------------
123
DblLnkLst_Init(DblLnkLst_Links *l) // IN
125
l->prev = l->next = l;
130
*----------------------------------------------------------------------
134
* Merge two doubly linked lists into one
136
* The operation is commutative
137
* The operation is inversible (its inverse is DblLnkLst_Unlink)
145
*----------------------------------------------------------------------
149
DblLnkLst_Link(DblLnkLst_Links *l1, // IN
150
DblLnkLst_Links *l2) // IN
152
DblLnkLst_Links *tmp;
154
(tmp = l1->prev)->next = l2;
155
(l1->prev = l2->prev)->next = l1;
161
*----------------------------------------------------------------------
163
* DblLnkLst_Unlink --
165
* Split one doubly linked list into two
167
* No check is performed: the caller must ensure that both members
168
* belong to the same doubly linked list
170
* The operation is commutative
171
* The operation is inversible (its inverse is DblLnkLst_Link)
179
*----------------------------------------------------------------------
183
DblLnkLst_Unlink(DblLnkLst_Links *l1, // IN
184
DblLnkLst_Links *l2) // IN
186
DblLnkLst_Links *tmp;
189
(l1->prev = l2->prev)->next = l1;
190
(l2->prev = tmp )->next = l2;
195
*----------------------------------------------------------------------
197
* DblLnkLst_Unlink1 --
199
* Unlink an element from its list.
207
*----------------------------------------------------------------------
211
DblLnkLst_Unlink1(DblLnkLst_Links *l) // IN
213
DblLnkLst_Unlink(l, l->next);
218
*----------------------------------------------------------------------------
220
* DblLnkLst_IsLinked --
222
* Determines whether an element is linked with any other elements.
225
* TRUE if link is linked, FALSE otherwise.
230
*----------------------------------------------------------------------------
234
DblLnkLst_IsLinked(DblLnkLst_Links const *l) // IN
237
* A DblLnkLst_Links is either linked to itself (not linked) or linked to
238
* other elements in a list (linked).
245
*----------------------------------------------------------------------
247
* DblLnkLst_LinkFirst --
249
* Insert 'l' at the beginning of the list anchored at 'head'
257
*----------------------------------------------------------------------
261
DblLnkLst_LinkFirst(DblLnkLst_Links *head, // IN
262
DblLnkLst_Links *l) // IN
264
DblLnkLst_Link(head->next, l);
269
*----------------------------------------------------------------------
271
* DblLnkLst_LinkLast --
273
* Insert 'l' at the end of the list anchored at 'head'
281
*----------------------------------------------------------------------
285
DblLnkLst_LinkLast(DblLnkLst_Links *head, // IN
286
DblLnkLst_Links *l) // IN
288
DblLnkLst_Link(head, l);
111
292
#endif /* _DBLLNKLST_H_ */