nsprpub/pr/include/prclist.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef prclist_h___
michael@0 7 #define prclist_h___
michael@0 8
michael@0 9 #include "prtypes.h"
michael@0 10
michael@0 11 typedef struct PRCListStr PRCList;
michael@0 12
michael@0 13 /*
michael@0 14 ** Circular linked list
michael@0 15 */
michael@0 16 struct PRCListStr {
michael@0 17 PRCList *next;
michael@0 18 PRCList *prev;
michael@0 19 };
michael@0 20
michael@0 21 /*
michael@0 22 ** Insert element "_e" into the list, before "_l".
michael@0 23 */
michael@0 24 #define PR_INSERT_BEFORE(_e,_l) \
michael@0 25 PR_BEGIN_MACRO \
michael@0 26 (_e)->next = (_l); \
michael@0 27 (_e)->prev = (_l)->prev; \
michael@0 28 (_l)->prev->next = (_e); \
michael@0 29 (_l)->prev = (_e); \
michael@0 30 PR_END_MACRO
michael@0 31
michael@0 32 /*
michael@0 33 ** Insert element "_e" into the list, after "_l".
michael@0 34 */
michael@0 35 #define PR_INSERT_AFTER(_e,_l) \
michael@0 36 PR_BEGIN_MACRO \
michael@0 37 (_e)->next = (_l)->next; \
michael@0 38 (_e)->prev = (_l); \
michael@0 39 (_l)->next->prev = (_e); \
michael@0 40 (_l)->next = (_e); \
michael@0 41 PR_END_MACRO
michael@0 42
michael@0 43 /*
michael@0 44 ** Return the element following element "_e"
michael@0 45 */
michael@0 46 #define PR_NEXT_LINK(_e) \
michael@0 47 ((_e)->next)
michael@0 48 /*
michael@0 49 ** Return the element preceding element "_e"
michael@0 50 */
michael@0 51 #define PR_PREV_LINK(_e) \
michael@0 52 ((_e)->prev)
michael@0 53
michael@0 54 /*
michael@0 55 ** Append an element "_e" to the end of the list "_l"
michael@0 56 */
michael@0 57 #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
michael@0 58
michael@0 59 /*
michael@0 60 ** Insert an element "_e" at the head of the list "_l"
michael@0 61 */
michael@0 62 #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
michael@0 63
michael@0 64 /* Return the head/tail of the list */
michael@0 65 #define PR_LIST_HEAD(_l) (_l)->next
michael@0 66 #define PR_LIST_TAIL(_l) (_l)->prev
michael@0 67
michael@0 68 /*
michael@0 69 ** Remove the element "_e" from it's circular list.
michael@0 70 */
michael@0 71 #define PR_REMOVE_LINK(_e) \
michael@0 72 PR_BEGIN_MACRO \
michael@0 73 (_e)->prev->next = (_e)->next; \
michael@0 74 (_e)->next->prev = (_e)->prev; \
michael@0 75 PR_END_MACRO
michael@0 76
michael@0 77 /*
michael@0 78 ** Remove the element "_e" from it's circular list. Also initializes the
michael@0 79 ** linkage.
michael@0 80 */
michael@0 81 #define PR_REMOVE_AND_INIT_LINK(_e) \
michael@0 82 PR_BEGIN_MACRO \
michael@0 83 (_e)->prev->next = (_e)->next; \
michael@0 84 (_e)->next->prev = (_e)->prev; \
michael@0 85 (_e)->next = (_e); \
michael@0 86 (_e)->prev = (_e); \
michael@0 87 PR_END_MACRO
michael@0 88
michael@0 89 /*
michael@0 90 ** Return non-zero if the given circular list "_l" is empty, zero if the
michael@0 91 ** circular list is not empty
michael@0 92 */
michael@0 93 #define PR_CLIST_IS_EMPTY(_l) \
michael@0 94 ((_l)->next == (_l))
michael@0 95
michael@0 96 /*
michael@0 97 ** Initialize a circular list
michael@0 98 */
michael@0 99 #define PR_INIT_CLIST(_l) \
michael@0 100 PR_BEGIN_MACRO \
michael@0 101 (_l)->next = (_l); \
michael@0 102 (_l)->prev = (_l); \
michael@0 103 PR_END_MACRO
michael@0 104
michael@0 105 #define PR_INIT_STATIC_CLIST(_l) \
michael@0 106 {(_l), (_l)}
michael@0 107
michael@0 108 #endif /* prclist_h___ */

mercurial