aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-08 05:28:47 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-08 05:28:47 +0000
commita45a413db3bdce126d5cb28ed49b776fdebb4b1d (patch)
tree444ea944312fd31b5524ee43f8cfc97e2884c6de /include/asterisk
parentbeabbf77e66fbdd59fdcb5e12dade8039fd0b683 (diff)
improve linked-list macros in two ways:
- the *_CURRENT macros no longer need the list head pointer argument - add AST_LIST_MOVE_CURRENT to encapsulate the remove/add operation when moving entries between lists git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89106 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk')
-rw-r--r--include/asterisk/linkedlists.h31
1 files changed, 19 insertions, 12 deletions
diff --git a/include/asterisk/linkedlists.h b/include/asterisk/linkedlists.h
index 21e38761a..1f3285dfa 100644
--- a/include/asterisk/linkedlists.h
+++ b/include/asterisk/linkedlists.h
@@ -496,10 +496,11 @@ struct { \
the \a current pointer without affecting the loop traversal.
*/
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field) { \
- typeof((head)->first) __list_next; \
- typeof((head)->first) __list_prev = NULL; \
- typeof((head)->first) __new_prev = NULL; \
- for ((var) = (head)->first, __new_prev = (var), \
+ typeof((head)) __list_head = head; \
+ typeof(__list_head->first) __list_next; \
+ typeof(__list_head->first) __list_prev = NULL; \
+ typeof(__list_head->first) __new_prev = NULL; \
+ for ((var) = __list_head->first, __new_prev = (var), \
__list_next = (var) ? (var)->field.next : NULL; \
(var); \
__list_prev = __new_prev, (var) = __list_next, \
@@ -511,7 +512,6 @@ struct { \
/*!
\brief Removes the \a current entry from a list during a traversal.
- \param head This is a pointer to the list head structure
\param field This is the name of the field (declared using AST_LIST_ENTRY())
used to link entries of this list together.
@@ -520,22 +520,29 @@ struct { \
the list traversal (and without having to re-traverse the list to modify the
previous entry, if any).
*/
-#define AST_LIST_REMOVE_CURRENT(head, field) do { \
+#define AST_LIST_REMOVE_CURRENT(field) do { \
__new_prev->field.next = NULL; \
__new_prev = __list_prev; \
if (__list_prev) \
__list_prev->field.next = __list_next; \
else \
- (head)->first = __list_next; \
+ __list_head->first = __list_next; \
if (!__list_next) \
- (head)->last = __list_prev; \
+ __list_head->last = __list_prev; \
} while (0)
#define AST_RWLIST_REMOVE_CURRENT AST_LIST_REMOVE_CURRENT
+#define AST_LIST_MOVE_CURRENT(newhead, field) do { \
+ typeof ((newhead)->first) __list_cur = __new_prev; \
+ AST_LIST_REMOVE_CURRENT(field); \
+ AST_LIST_INSERT_TAIL((newhead), __list_cur, field); \
+ } while (0)
+
+#define AST_RWLIST_MOVE_CURRENT AST_LIST_MOVE_CURRENT
+
/*!
\brief Inserts a list entry before the current entry during a traversal.
- \param head This is a pointer to the list head structure
\param elm This is a pointer to the entry to be inserted.
\param field This is the name of the field (declared using AST_LIST_ENTRY())
used to link entries of this list together.
@@ -543,13 +550,13 @@ struct { \
\note This macro can \b only be used inside an AST_LIST_TRAVERSE_SAFE_BEGIN()
block.
*/
-#define AST_LIST_INSERT_BEFORE_CURRENT(head, elm, field) do { \
+#define AST_LIST_INSERT_BEFORE_CURRENT(elm, field) do { \
if (__list_prev) { \
(elm)->field.next = __list_prev->field.next; \
__list_prev->field.next = elm; \
} else { \
- (elm)->field.next = (head)->first; \
- (head)->first = (elm); \
+ (elm)->field.next = __list_head->first; \
+ __list_head->first = (elm); \
} \
__new_prev = (elm); \
} while (0)