Skip to content
Snippets Groups Projects
Commit 224dd2f6 authored by Richard Mudgett's avatar Richard Mudgett
Browse files

Made AST_LIST_REMOVE() simpler and use better names.

* Update doxygen of AST_LIST_REMOVE().
........

Merged revisions 376627 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 376628 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@376629 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent c4f013c5
No related branches found
No related tags found
No related merge requests found
...@@ -848,34 +848,38 @@ struct { \ ...@@ -848,34 +848,38 @@ struct { \
* \param elm This is a pointer to the entry to be removed. * \param elm This is a pointer to the entry to be removed.
* \param field This is the name of the field (declared using AST_LIST_ENTRY()) * \param field This is the name of the field (declared using AST_LIST_ENTRY())
* used to link entries of this list together. * used to link entries of this list together.
* \warning The removed entry is \b not freed nor modified in any way. * \retval elm if elm was in the list.
*/ * \retval NULL if elm was not in the list or elm was NULL.
#define AST_LIST_REMOVE(head, elm, field) ({ \ * \warning The removed entry is \b not freed.
__typeof(elm) __res = NULL; \ */
__typeof(elm) __tmp = elm; \ #define AST_LIST_REMOVE(head, elm, field) \
if (!__tmp) { \ ({ \
__res = NULL; \ __typeof(elm) __elm = (elm); \
} else if ((head)->first == (elm)) { \ if (__elm) { \
__res = (head)->first; \ if ((head)->first == __elm) { \
(head)->first = (elm)->field.next; \ (head)->first = __elm->field.next; \
if ((head)->last == (elm)) \ __elm->field.next = NULL; \
(head)->last = NULL; \ if ((head)->last == __elm) { \
} else { \ (head)->last = NULL; \
typeof(elm) curelm = (head)->first; \ } \
while (curelm && (curelm->field.next != (elm))) \ } else { \
curelm = curelm->field.next; \ typeof(elm) __prev = (head)->first; \
if (curelm) { \ while (__prev && __prev->field.next != __elm) { \
__res = (elm); \ __prev = __prev->field.next; \
curelm->field.next = (elm)->field.next; \ } \
if ((head)->last == (elm)) \ if (__prev) { \
(head)->last = curelm; \ __prev->field.next = __elm->field.next; \
} \ __elm->field.next = NULL; \
} \ if ((head)->last == __elm) { \
if (__res) { \ (head)->last = __prev; \
(__res)->field.next = NULL; \ } \
} \ } else { \
(__res); \ __elm = NULL; \
}) } \
} \
} \
__elm; \
})
#define AST_RWLIST_REMOVE AST_LIST_REMOVE #define AST_RWLIST_REMOVE AST_LIST_REMOVE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment