1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/prclist.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef prclist_h___ 1.10 +#define prclist_h___ 1.11 + 1.12 +#include "prtypes.h" 1.13 + 1.14 +typedef struct PRCListStr PRCList; 1.15 + 1.16 +/* 1.17 +** Circular linked list 1.18 +*/ 1.19 +struct PRCListStr { 1.20 + PRCList *next; 1.21 + PRCList *prev; 1.22 +}; 1.23 + 1.24 +/* 1.25 +** Insert element "_e" into the list, before "_l". 1.26 +*/ 1.27 +#define PR_INSERT_BEFORE(_e,_l) \ 1.28 + PR_BEGIN_MACRO \ 1.29 + (_e)->next = (_l); \ 1.30 + (_e)->prev = (_l)->prev; \ 1.31 + (_l)->prev->next = (_e); \ 1.32 + (_l)->prev = (_e); \ 1.33 + PR_END_MACRO 1.34 + 1.35 +/* 1.36 +** Insert element "_e" into the list, after "_l". 1.37 +*/ 1.38 +#define PR_INSERT_AFTER(_e,_l) \ 1.39 + PR_BEGIN_MACRO \ 1.40 + (_e)->next = (_l)->next; \ 1.41 + (_e)->prev = (_l); \ 1.42 + (_l)->next->prev = (_e); \ 1.43 + (_l)->next = (_e); \ 1.44 + PR_END_MACRO 1.45 + 1.46 +/* 1.47 +** Return the element following element "_e" 1.48 +*/ 1.49 +#define PR_NEXT_LINK(_e) \ 1.50 + ((_e)->next) 1.51 +/* 1.52 +** Return the element preceding element "_e" 1.53 +*/ 1.54 +#define PR_PREV_LINK(_e) \ 1.55 + ((_e)->prev) 1.56 + 1.57 +/* 1.58 +** Append an element "_e" to the end of the list "_l" 1.59 +*/ 1.60 +#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l) 1.61 + 1.62 +/* 1.63 +** Insert an element "_e" at the head of the list "_l" 1.64 +*/ 1.65 +#define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l) 1.66 + 1.67 +/* Return the head/tail of the list */ 1.68 +#define PR_LIST_HEAD(_l) (_l)->next 1.69 +#define PR_LIST_TAIL(_l) (_l)->prev 1.70 + 1.71 +/* 1.72 +** Remove the element "_e" from it's circular list. 1.73 +*/ 1.74 +#define PR_REMOVE_LINK(_e) \ 1.75 + PR_BEGIN_MACRO \ 1.76 + (_e)->prev->next = (_e)->next; \ 1.77 + (_e)->next->prev = (_e)->prev; \ 1.78 + PR_END_MACRO 1.79 + 1.80 +/* 1.81 +** Remove the element "_e" from it's circular list. Also initializes the 1.82 +** linkage. 1.83 +*/ 1.84 +#define PR_REMOVE_AND_INIT_LINK(_e) \ 1.85 + PR_BEGIN_MACRO \ 1.86 + (_e)->prev->next = (_e)->next; \ 1.87 + (_e)->next->prev = (_e)->prev; \ 1.88 + (_e)->next = (_e); \ 1.89 + (_e)->prev = (_e); \ 1.90 + PR_END_MACRO 1.91 + 1.92 +/* 1.93 +** Return non-zero if the given circular list "_l" is empty, zero if the 1.94 +** circular list is not empty 1.95 +*/ 1.96 +#define PR_CLIST_IS_EMPTY(_l) \ 1.97 + ((_l)->next == (_l)) 1.98 + 1.99 +/* 1.100 +** Initialize a circular list 1.101 +*/ 1.102 +#define PR_INIT_CLIST(_l) \ 1.103 + PR_BEGIN_MACRO \ 1.104 + (_l)->next = (_l); \ 1.105 + (_l)->prev = (_l); \ 1.106 + PR_END_MACRO 1.107 + 1.108 +#define PR_INIT_STATIC_CLIST(_l) \ 1.109 + {(_l), (_l)} 1.110 + 1.111 +#endif /* prclist_h___ */