Bumping manifests a=b2g-bump
[gecko.git] / js / src / jsclist.h
blobb8455152c63cbc6d3ebcc7eb27abe2aadf645338
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jsclist_h
8 #define jsclist_h
10 #include "jstypes.h"
13 ** Circular linked list
15 typedef struct JSCListStr {
16 struct JSCListStr* next;
17 struct JSCListStr* prev;
18 } JSCList;
21 ** Insert element "_e" into the list, before "_l".
23 #define JS_INSERT_BEFORE(_e,_l) \
24 JS_BEGIN_MACRO \
25 (_e)->next = (_l); \
26 (_e)->prev = (_l)->prev; \
27 (_l)->prev->next = (_e); \
28 (_l)->prev = (_e); \
29 JS_END_MACRO
32 ** Insert element "_e" into the list, after "_l".
34 #define JS_INSERT_AFTER(_e,_l) \
35 JS_BEGIN_MACRO \
36 (_e)->next = (_l)->next; \
37 (_e)->prev = (_l); \
38 (_l)->next->prev = (_e); \
39 (_l)->next = (_e); \
40 JS_END_MACRO
43 ** Return the element following element "_e"
45 #define JS_NEXT_LINK(_e) \
46 ((_e)->next)
48 ** Return the element preceding element "_e"
50 #define JS_PREV_LINK(_e) \
51 ((_e)->prev)
54 ** Append an element "_e" to the end of the list "_l"
56 #define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
59 ** Insert an element "_e" at the head of the list "_l"
61 #define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
63 /* Return the head/tail of the list */
64 #define JS_LIST_HEAD(_l) (_l)->next
65 #define JS_LIST_TAIL(_l) (_l)->prev
68 ** Remove the element "_e" from it's circular list.
70 #define JS_REMOVE_LINK(_e) \
71 JS_BEGIN_MACRO \
72 (_e)->prev->next = (_e)->next; \
73 (_e)->next->prev = (_e)->prev; \
74 JS_END_MACRO
77 ** Remove the element "_e" from it's circular list. Also initializes the
78 ** linkage.
80 #define JS_REMOVE_AND_INIT_LINK(_e) \
81 JS_BEGIN_MACRO \
82 (_e)->prev->next = (_e)->next; \
83 (_e)->next->prev = (_e)->prev; \
84 (_e)->next = (_e); \
85 (_e)->prev = (_e); \
86 JS_END_MACRO
89 ** Return non-zero if the given circular list "_l" is empty, zero if the
90 ** circular list is not empty
92 #define JS_CLIST_IS_EMPTY(_l) \
93 bool((_l)->next == (_l))
96 ** Initialize a circular list
98 #define JS_INIT_CLIST(_l) \
99 JS_BEGIN_MACRO \
100 (_l)->next = (_l); \
101 (_l)->prev = (_l); \
102 JS_END_MACRO
104 #define JS_INIT_STATIC_CLIST(_l) \
105 {(_l), (_l)}
107 #endif /* jsclist_h */