andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef prclist_h___ andre@0: #define prclist_h___ andre@0: andre@0: #include "prtypes.h" andre@0: andre@0: typedef struct PRCListStr PRCList; andre@0: andre@0: /* andre@0: ** Circular linked list andre@0: */ andre@0: struct PRCListStr { andre@0: PRCList *next; andre@0: PRCList *prev; andre@0: }; andre@0: andre@0: /* andre@0: ** Insert element "_e" into the list, before "_l". andre@0: */ andre@0: #define PR_INSERT_BEFORE(_e,_l) \ andre@0: PR_BEGIN_MACRO \ andre@0: (_e)->next = (_l); \ andre@0: (_e)->prev = (_l)->prev; \ andre@0: (_l)->prev->next = (_e); \ andre@0: (_l)->prev = (_e); \ andre@0: PR_END_MACRO andre@0: andre@0: /* andre@0: ** Insert element "_e" into the list, after "_l". andre@0: */ andre@0: #define PR_INSERT_AFTER(_e,_l) \ andre@0: PR_BEGIN_MACRO \ andre@0: (_e)->next = (_l)->next; \ andre@0: (_e)->prev = (_l); \ andre@0: (_l)->next->prev = (_e); \ andre@0: (_l)->next = (_e); \ andre@0: PR_END_MACRO andre@0: andre@0: /* andre@0: ** Return the element following element "_e" andre@0: */ andre@0: #define PR_NEXT_LINK(_e) \ andre@0: ((_e)->next) andre@0: /* andre@0: ** Return the element preceding element "_e" andre@0: */ andre@0: #define PR_PREV_LINK(_e) \ andre@0: ((_e)->prev) andre@0: andre@0: /* andre@0: ** Append an element "_e" to the end of the list "_l" andre@0: */ andre@0: #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l) andre@0: andre@0: /* andre@0: ** Insert an element "_e" at the head of the list "_l" andre@0: */ andre@0: #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l) andre@0: andre@0: /* Return the head/tail of the list */ andre@0: #define PR_LIST_HEAD(_l) (_l)->next andre@0: #define PR_LIST_TAIL(_l) (_l)->prev andre@0: andre@0: /* andre@0: ** Remove the element "_e" from it's circular list. andre@0: */ andre@0: #define PR_REMOVE_LINK(_e) \ andre@0: PR_BEGIN_MACRO \ andre@0: (_e)->prev->next = (_e)->next; \ andre@0: (_e)->next->prev = (_e)->prev; \ andre@0: PR_END_MACRO andre@0: andre@0: /* andre@0: ** Remove the element "_e" from it's circular list. Also initializes the andre@0: ** linkage. andre@0: */ andre@0: #define PR_REMOVE_AND_INIT_LINK(_e) \ andre@0: PR_BEGIN_MACRO \ andre@0: (_e)->prev->next = (_e)->next; \ andre@0: (_e)->next->prev = (_e)->prev; \ andre@0: (_e)->next = (_e); \ andre@0: (_e)->prev = (_e); \ andre@0: PR_END_MACRO andre@0: andre@0: /* andre@0: ** Return non-zero if the given circular list "_l" is empty, zero if the andre@0: ** circular list is not empty andre@0: */ andre@0: #define PR_CLIST_IS_EMPTY(_l) \ andre@0: ((_l)->next == (_l)) andre@0: andre@0: /* andre@0: ** Initialize a circular list andre@0: */ andre@0: #define PR_INIT_CLIST(_l) \ andre@0: PR_BEGIN_MACRO \ andre@0: (_l)->next = (_l); \ andre@0: (_l)->prev = (_l); \ andre@0: PR_END_MACRO andre@0: andre@0: #define PR_INIT_STATIC_CLIST(_l) \ andre@0: {(_l), (_l)} andre@0: andre@0: #endif /* prclist_h___ */