00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2007, Digium, Inc. 00005 * 00006 * Steve Murphy <murf@digium.com> 00007 * 00008 * Doubly-Linked List Macros-- 00009 * Based on linkedlists.h (to the point of plagiarism!), which is by: 00010 * 00011 * Mark Spencer <markster@digium.com> 00012 * Kevin P. Fleming <kpfleming@digium.com> 00013 * 00014 * See http://www.asterisk.org for more information about 00015 * the Asterisk project. Please do not directly contact 00016 * any of the maintainers of this project for assistance; 00017 * the project provides a web site, mailing lists and IRC 00018 * channels for your use. 00019 * 00020 * This program is free software, distributed under the terms of 00021 * the GNU General Public License Version 2. See the LICENSE file 00022 * at the top of the source tree. 00023 */ 00024 00025 #ifndef ASTERISK_DLINKEDLISTS_H 00026 #define ASTERISK_DLINKEDLISTS_H 00027 00028 #include "asterisk/lock.h" 00029 00030 /*! 00031 * \file dlinkedlists.h 00032 * \brief A set of macros to manage doubly-linked lists. 00033 */ 00034 00035 /*! 00036 * \brief Locks a list. 00037 * \param head This is a pointer to the list head structure 00038 * 00039 * This macro attempts to place an exclusive lock in the 00040 * list head structure pointed to by head. 00041 * \retval 0 on success 00042 * \retval non-zero on failure 00043 * \since 1.6.1 00044 */ 00045 #define AST_DLLIST_LOCK(head) \ 00046 ast_mutex_lock(&(head)->lock) 00047 00048 /*! 00049 * \brief Write locks a list. 00050 * \param head This is a pointer to the list head structure 00051 * 00052 * This macro attempts to place an exclusive write lock in the 00053 * list head structure pointed to by head. 00054 * \retval 0 on success 00055 * \retval non-zero on failure 00056 * \since 1.6.1 00057 */ 00058 #define AST_RWDLLIST_WRLOCK(head) \ 00059 ast_rwlock_wrlock(&(head)->lock) 00060 00061 /*! 00062 * \brief Read locks a list. 00063 * \param head This is a pointer to the list head structure 00064 * 00065 * This macro attempts to place a read lock in the 00066 * list head structure pointed to by head. 00067 * \retval 0 on success 00068 * \retval non-zero on failure 00069 * \since 1.6.1 00070 */ 00071 #define AST_RWDLLIST_RDLOCK(head) \ 00072 ast_rwlock_rdlock(&(head)->lock) 00073 00074 /*! 00075 * \brief Locks a list, without blocking if the list is locked. 00076 * \param head This is a pointer to the list head structure 00077 * 00078 * This macro attempts to place an exclusive lock in the 00079 * list head structure pointed to by head. 00080 * \retval 0 on success 00081 * \retval non-zero on failure 00082 * \since 1.6.1 00083 */ 00084 #define AST_DLLIST_TRYLOCK(head) \ 00085 ast_mutex_trylock(&(head)->lock) 00086 00087 /*! 00088 * \brief Write locks a list, without blocking if the list is locked. 00089 * \param head This is a pointer to the list head structure 00090 * 00091 * This macro attempts to place an exclusive write lock in the 00092 * list head structure pointed to by head. 00093 * \retval 0 on success 00094 * \retval non-zero on failure 00095 * \since 1.6.1 00096 */ 00097 #define AST_RWDLLIST_TRYWRLOCK(head) \ 00098 ast_rwlock_trywrlock(&(head)->lock) 00099 00100 /*! 00101 * \brief Read locks a list, without blocking if the list is locked. 00102 * \param head This is a pointer to the list head structure 00103 * 00104 * This macro attempts to place a read lock in the 00105 * list head structure pointed to by head. 00106 * \retval 0 on success 00107 * \retval non-zero on failure 00108 * \since 1.6.1 00109 */ 00110 #define AST_RWDLLIST_TRYRDLOCK(head) \ 00111 ast_rwlock_tryrdlock(&(head)->lock) 00112 00113 /*! 00114 * \brief Attempts to unlock a list. 00115 * \param head This is a pointer to the list head structure 00116 * 00117 * This macro attempts to remove an exclusive lock from the 00118 * list head structure pointed to by head. If the list 00119 * was not locked by this thread, this macro has no effect. 00120 * \since 1.6.1 00121 */ 00122 #define AST_DLLIST_UNLOCK(head) \ 00123 ast_mutex_unlock(&(head)->lock) 00124 00125 /*! 00126 * \brief Attempts to unlock a read/write based list. 00127 * \param head This is a pointer to the list head structure 00128 * 00129 * This macro attempts to remove a read or write lock from the 00130 * list head structure pointed to by head. If the list 00131 * was not locked by this thread, this macro has no effect. 00132 * \since 1.6.1 00133 */ 00134 #define AST_RWDLLIST_UNLOCK(head) \ 00135 ast_rwlock_unlock(&(head)->lock) 00136 00137 /*! 00138 * \brief Defines a structure to be used to hold a list of specified type. 00139 * \param name This will be the name of the defined structure. 00140 * \param type This is the type of each list entry. 00141 * 00142 * This macro creates a structure definition that can be used 00143 * to hold a list of the entries of type \a type. It does not actually 00144 * declare (allocate) a structure; to do that, either follow this 00145 * macro with the desired name of the instance you wish to declare, 00146 * or use the specified \a name to declare instances elsewhere. 00147 * 00148 * Example usage: 00149 * \code 00150 * static AST_DLLIST_HEAD(entry_list, entry) entries; 00151 * \endcode 00152 * 00153 * This would define \c struct \c entry_list, and declare an instance of it named 00154 * \a entries, all intended to hold a list of type \c struct \c entry. 00155 * \since 1.6.1 00156 */ 00157 #define AST_DLLIST_HEAD(name, type) \ 00158 struct name { \ 00159 struct type *first; \ 00160 struct type *last; \ 00161 ast_mutex_t lock; \ 00162 } 00163 00164 /*! 00165 * \brief Defines a structure to be used to hold a read/write list of specified type. 00166 * \param name This will be the name of the defined structure. 00167 * \param type This is the type of each list entry. 00168 * 00169 * This macro creates a structure definition that can be used 00170 * to hold a list of the entries of type \a type. It does not actually 00171 * declare (allocate) a structure; to do that, either follow this 00172 * macro with the desired name of the instance you wish to declare, 00173 * or use the specified \a name to declare instances elsewhere. 00174 * 00175 * Example usage: 00176 * \code 00177 * static AST_RWDLLIST_HEAD(entry_list, entry) entries; 00178 * \endcode 00179 * 00180 * This would define \c struct \c entry_list, and declare an instance of it named 00181 * \a entries, all intended to hold a list of type \c struct \c entry. 00182 * \since 1.6.1 00183 */ 00184 #define AST_RWDLLIST_HEAD(name, type) \ 00185 struct name { \ 00186 struct type *first; \ 00187 struct type *last; \ 00188 ast_rwlock_t lock; \ 00189 } 00190 00191 /*! 00192 * \brief Defines a structure to be used to hold a list of specified type (with no lock). 00193 * \param name This will be the name of the defined structure. 00194 * \param type This is the type of each list entry. 00195 * 00196 * This macro creates a structure definition that can be used 00197 * to hold a list of the entries of type \a type. It does not actually 00198 * declare (allocate) a structure; to do that, either follow this 00199 * macro with the desired name of the instance you wish to declare, 00200 * or use the specified \a name to declare instances elsewhere. 00201 * 00202 * Example usage: 00203 * \code 00204 * static AST_DLLIST_HEAD_NOLOCK(entry_list, entry) entries; 00205 * \endcode 00206 * 00207 * This would define \c struct \c entry_list, and declare an instance of it named 00208 * \a entries, all intended to hold a list of type \c struct \c entry. 00209 * \since 1.6.1 00210 */ 00211 #define AST_DLLIST_HEAD_NOLOCK(name, type) \ 00212 struct name { \ 00213 struct type *first; \ 00214 struct type *last; \ 00215 } 00216 00217 /*! 00218 * \brief Defines initial values for a declaration of AST_DLLIST_HEAD 00219 * \since 1.6.1 00220 */ 00221 #define AST_DLLIST_HEAD_INIT_VALUE \ 00222 { \ 00223 .first = NULL, \ 00224 .last = NULL, \ 00225 .lock = AST_MUTEX_INIT_VALUE, \ 00226 } 00227 00228 /*! 00229 * \brief Defines initial values for a declaration of AST_RWDLLIST_HEAD 00230 * \since 1.6.1 00231 */ 00232 #define AST_RWDLLIST_HEAD_INIT_VALUE \ 00233 { \ 00234 .first = NULL, \ 00235 .last = NULL, \ 00236 .lock = AST_RWLOCK_INIT_VALUE, \ 00237 } 00238 00239 /*! 00240 * \brief Defines initial values for a declaration of AST_DLLIST_HEAD_NOLOCK 00241 * \since 1.6.1 00242 */ 00243 #define AST_DLLIST_HEAD_NOLOCK_INIT_VALUE \ 00244 { \ 00245 .first = NULL, \ 00246 .last = NULL, \ 00247 } 00248 00249 /*! 00250 * \brief Defines a structure to be used to hold a list of specified type, statically initialized. 00251 * \param name This will be the name of the defined structure. 00252 * \param type This is the type of each list entry. 00253 * 00254 * This macro creates a structure definition that can be used 00255 * to hold a list of the entries of type \a type, and allocates an instance 00256 * of it, initialized to be empty. 00257 * 00258 * Example usage: 00259 * \code 00260 * static AST_DLLIST_HEAD_STATIC(entry_list, entry); 00261 * \endcode 00262 * 00263 * This would define \c struct \c entry_list, intended to hold a list of 00264 * type \c struct \c entry. 00265 * \since 1.6.1 00266 */ 00267 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) 00268 #define AST_DLLIST_HEAD_STATIC(name, type) \ 00269 struct name { \ 00270 struct type *first; \ 00271 struct type *last; \ 00272 ast_mutex_t lock; \ 00273 } name; \ 00274 static void __attribute__((constructor)) __init_##name(void) \ 00275 { \ 00276 AST_DLLIST_HEAD_INIT(&name); \ 00277 } \ 00278 static void __attribute__((destructor)) __fini_##name(void) \ 00279 { \ 00280 AST_DLLIST_HEAD_DESTROY(&name); \ 00281 } \ 00282 struct __dummy_##name 00283 #else 00284 #define AST_DLLIST_HEAD_STATIC(name, type) \ 00285 struct name { \ 00286 struct type *first; \ 00287 struct type *last; \ 00288 ast_mutex_t lock; \ 00289 } name = AST_DLLIST_HEAD_INIT_VALUE 00290 #endif 00291 00292 /*! 00293 * \brief Defines a structure to be used to hold a read/write list of specified type, statically initialized. 00294 * \param name This will be the name of the defined structure. 00295 * \param type This is the type of each list entry. 00296 * 00297 * This macro creates a structure definition that can be used 00298 * to hold a list of the entries of type \a type, and allocates an instance 00299 * of it, initialized to be empty. 00300 * 00301 * Example usage: 00302 * \code 00303 * static AST_RWDLLIST_HEAD_STATIC(entry_list, entry); 00304 * \endcode 00305 * 00306 * This would define \c struct \c entry_list, intended to hold a list of 00307 * type \c struct \c entry. 00308 * \since 1.6.1 00309 */ 00310 #ifndef HAVE_PTHREAD_RWLOCK_INITIALIZER 00311 #define AST_RWDLLIST_HEAD_STATIC(name, type) \ 00312 struct name { \ 00313 struct type *first; \ 00314 struct type *last; \ 00315 ast_rwlock_t lock; \ 00316 } name; \ 00317 static void __attribute__((constructor)) __init_##name(void) \ 00318 { \ 00319 AST_RWDLLIST_HEAD_INIT(&name); \ 00320 } \ 00321 static void __attribute__((destructor)) __fini_##name(void) \ 00322 { \ 00323 AST_RWDLLIST_HEAD_DESTROY(&name); \ 00324 } \ 00325 struct __dummy_##name 00326 #else 00327 #define AST_RWDLLIST_HEAD_STATIC(name, type) \ 00328 struct name { \ 00329 struct type *first; \ 00330 struct type *last; \ 00331 ast_rwlock_t lock; \ 00332 } name = AST_RWDLLIST_HEAD_INIT_VALUE 00333 #endif 00334 00335 /*! 00336 * \brief Defines a structure to be used to hold a list of specified type, statically initialized. 00337 * 00338 * This is the same as AST_DLLIST_HEAD_STATIC, except without the lock included. 00339 * \since 1.6.1 00340 */ 00341 #define AST_DLLIST_HEAD_NOLOCK_STATIC(name, type) \ 00342 struct name { \ 00343 struct type *first; \ 00344 struct type *last; \ 00345 } name = AST_DLLIST_HEAD_NOLOCK_INIT_VALUE 00346 00347 /*! 00348 * \brief Initializes a list head structure with a specified first entry. 00349 * \param head This is a pointer to the list head structure 00350 * \param entry pointer to the list entry that will become the head of the list 00351 * 00352 * This macro initializes a list head structure by setting the head 00353 * entry to the supplied value and recreating the embedded lock. 00354 * \since 1.6.1 00355 */ 00356 #define AST_DLLIST_HEAD_SET(head, entry) \ 00357 do { \ 00358 (head)->first = (entry); \ 00359 (head)->last = (entry); \ 00360 ast_mutex_init(&(head)->lock); \ 00361 } while (0) 00362 00363 /*! 00364 * \brief Initializes an rwlist head structure with a specified first entry. 00365 * \param head This is a pointer to the list head structure 00366 * \param entry pointer to the list entry that will become the head of the list 00367 * 00368 * This macro initializes a list head structure by setting the head 00369 * entry to the supplied value and recreating the embedded lock. 00370 * \since 1.6.1 00371 */ 00372 #define AST_RWDLLIST_HEAD_SET(head, entry) \ 00373 do { \ 00374 (head)->first = (entry); \ 00375 (head)->last = (entry); \ 00376 ast_rwlock_init(&(head)->lock); \ 00377 } while (0) 00378 00379 /*! 00380 * \brief Initializes a list head structure with a specified first entry. 00381 * \param head This is a pointer to the list head structure 00382 * \param entry pointer to the list entry that will become the head of the list 00383 * 00384 * This macro initializes a list head structure by setting the head 00385 * entry to the supplied value. 00386 * \since 1.6.1 00387 */ 00388 #define AST_DLLIST_HEAD_SET_NOLOCK(head, entry) \ 00389 do { \ 00390 (head)->first = (entry); \ 00391 (head)->last = (entry); \ 00392 } while (0) 00393 00394 /*! 00395 * \brief Declare previous/forward links inside a list entry. 00396 * \param type This is the type of each list entry. 00397 * 00398 * This macro declares a structure to be used to doubly link list entries together. 00399 * It must be used inside the definition of the structure named in 00400 * \a type, as follows: 00401 * 00402 * \code 00403 * struct list_entry { 00404 * ... 00405 * AST_DLLIST_ENTRY(list_entry) list; 00406 * } 00407 * \endcode 00408 * 00409 * The field name \a list here is arbitrary, and can be anything you wish. 00410 * \since 1.6.1 00411 */ 00412 #define AST_DLLIST_ENTRY(type) AST_DLLIST_HEAD_NOLOCK(, type) 00413 00414 #define AST_RWDLLIST_ENTRY AST_DLLIST_ENTRY 00415 00416 /*! 00417 * \brief Returns the first entry contained in a list. 00418 * \param head This is a pointer to the list head structure 00419 * \since 1.6.1 00420 */ 00421 #define AST_DLLIST_FIRST(head) ((head)->first) 00422 00423 #define AST_RWDLLIST_FIRST AST_DLLIST_FIRST 00424 00425 /*! 00426 * \brief Returns the last entry contained in a list. 00427 * \param head This is a pointer to the list head structure 00428 * \since 1.6.1 00429 */ 00430 #define AST_DLLIST_LAST(head) ((head)->last) 00431 00432 #define AST_RWDLLIST_LAST AST_DLLIST_LAST 00433 00434 #define AST_DLLIST_NEXT_DIRECTION(elm, field, direction) ((elm)->field.direction) 00435 00436 #define AST_RWDLLIST_NEXT_DIRECTION AST_DLLIST_NEXT_DIRECTION 00437 00438 /*! 00439 * \brief Returns the next entry in the list after the given entry. 00440 * \param elm This is a pointer to the current entry. 00441 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00442 * used to link entries of this list together. 00443 * \since 1.6.1 00444 */ 00445 #define AST_DLLIST_NEXT(elm, field) AST_DLLIST_NEXT_DIRECTION(elm, field, first) 00446 00447 #define AST_RWDLLIST_NEXT AST_DLLIST_NEXT 00448 00449 /*! 00450 * \brief Returns the previous entry in the list before the given entry. 00451 * \param elm This is a pointer to the current entry. 00452 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00453 * used to link entries of this list together. 00454 * \since 1.6.1 00455 */ 00456 #define AST_DLLIST_PREV(elm, field) AST_DLLIST_NEXT_DIRECTION(elm, field, last) 00457 00458 #define AST_RWDLLIST_PREV AST_DLLIST_PREV 00459 00460 /*! 00461 * \brief Checks whether the specified list contains any entries. 00462 * \param head This is a pointer to the list head structure 00463 * 00464 * \return non-zero if the list has entries 00465 * \return zero if not. 00466 * \since 1.6.1 00467 */ 00468 #define AST_DLLIST_EMPTY(head) (AST_DLLIST_FIRST(head) == NULL) 00469 00470 #define AST_RWDLLIST_EMPTY AST_DLLIST_EMPTY 00471 00472 /*! 00473 * \brief Checks whether the specified list contains the element. 00474 * \param head This is a pointer to the list head structure 00475 * \param elm This is a pointer to the list element to see if in list. 00476 * \param field List node field for the next node information. 00477 * 00478 * \return elm if the list has elm in it. 00479 * \return NULL if not. 00480 * \since 11 00481 */ 00482 #define AST_DLLIST_IS_MEMBER(head, elm, field) \ 00483 ({ \ 00484 typeof((head)->first) __cur; \ 00485 typeof((elm)) __elm = (elm); \ 00486 if (!__elm) { \ 00487 __cur = NULL; \ 00488 } else { \ 00489 __cur = (head)->first; \ 00490 while (__cur && __cur != __elm) { \ 00491 __cur = __cur->field.first; \ 00492 } \ 00493 } \ 00494 __cur; \ 00495 }) 00496 00497 #define AST_RWDLLIST_IS_MEMBER AST_DLLIST_IS_MEMBER 00498 00499 /*! 00500 * \brief Traverse a doublly linked list using the specified direction list. 00501 * 00502 * \param head List head structure pointer. 00503 * \param var This is the name of the variable that will hold a pointer to the 00504 * current list node on each iteration. It must be declared before calling 00505 * this macro. 00506 * \param field List node field for the next node information. (declared using AST_DLLIST_ENTRY()) 00507 * \param start Specified list node to start traversal: first or last 00508 * 00509 * This macro is use to loop over (traverse) the nodes in a list. It uses a 00510 * \a for loop, and supplies the enclosed code with a pointer to each list 00511 * node as it loops. It is typically used as follows: 00512 * \code 00513 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00514 * ... 00515 * struct list_entry { 00516 * ... 00517 * AST_DLLIST_ENTRY(list_entry) list; 00518 * } 00519 * ... 00520 * struct list_entry *current; 00521 * ... 00522 * AST_DLLIST_TRAVERSE_DIRECTION(&entries, current, list, first) { 00523 * (do something with current here (travers list in forward direction)) 00524 * } 00525 * ... 00526 * AST_DLLIST_TRAVERSE_DIRECTION(&entries, current, list, last) { 00527 * (do something with current here (travers list in reverse direction)) 00528 * } 00529 * \endcode 00530 * 00531 * \since 11 00532 */ 00533 #define AST_DLLIST_TRAVERSE_DIRECTION(head, var, field, start) \ 00534 for ((var) = (head)->start; (var); (var) = AST_DLLIST_NEXT_DIRECTION(var, field, start)) 00535 00536 #define AST_RWDLLIST_TRAVERSE_DIRECTION AST_DLLIST_TRAVERSE_DIRECTION 00537 00538 /*! 00539 * \brief Loops over (traverses) the entries in a list. 00540 * \param head This is a pointer to the list head structure 00541 * \param var This is the name of the variable that will hold a pointer to the 00542 * current list entry on each iteration. It must be declared before calling 00543 * this macro. 00544 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00545 * used to link entries of this list together. 00546 * 00547 * This macro is use to loop over (traverse) the entries in a list. It uses a 00548 * \a for loop, and supplies the enclosed code with a pointer to each list 00549 * entry as it loops. It is typically used as follows: 00550 * \code 00551 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00552 * ... 00553 * struct list_entry { 00554 * ... 00555 * AST_DLLIST_ENTRY(list_entry) list; 00556 * } 00557 * ... 00558 * struct list_entry *current; 00559 * ... 00560 * AST_DLLIST_TRAVERSE(&entries, current, list) { 00561 * (do something with current here) 00562 * } 00563 * \endcode 00564 * \warning If you modify the forward-link pointer contained in the \a current entry while 00565 * inside the loop, the behavior will be unpredictable. At a minimum, the following 00566 * macros will modify the forward-link pointer, and should not be used inside 00567 * AST_DLLIST_TRAVERSE() against the entry pointed to by the \a current pointer without 00568 * careful consideration of their consequences: 00569 * \li AST_DLLIST_NEXT() (when used as an lvalue) 00570 * \li AST_DLLIST_INSERT_AFTER() 00571 * \li AST_DLLIST_INSERT_HEAD() 00572 * \li AST_DLLIST_INSERT_TAIL() 00573 * \since 1.6.1 00574 */ 00575 #define AST_DLLIST_TRAVERSE(head,var,field) \ 00576 AST_DLLIST_TRAVERSE_DIRECTION(head, var, field, first) 00577 00578 #define AST_RWDLLIST_TRAVERSE AST_DLLIST_TRAVERSE 00579 00580 /*! 00581 * \brief Loops over (traverses) the entries in a list in reverse order, starting at the end. 00582 * \param head This is a pointer to the list head structure 00583 * \param var This is the name of the variable that will hold a pointer to the 00584 * current list entry on each iteration. It must be declared before calling 00585 * this macro. 00586 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00587 * used to link entries of this list together. 00588 * 00589 * This macro is use to loop over (traverse) the entries in a list in reverse order. It uses a 00590 * \a for loop, and supplies the enclosed code with a pointer to each list 00591 * entry as it loops. It is typically used as follows: 00592 * \code 00593 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00594 * ... 00595 * struct list_entry { 00596 * ... 00597 * AST_DLLIST_ENTRY(list_entry) list; 00598 * } 00599 * ... 00600 * struct list_entry *current; 00601 * ... 00602 * AST_DLLIST_TRAVERSE_BACKWARDS(&entries, current, list) { 00603 * (do something with current here) 00604 * } 00605 * \endcode 00606 * \warning If you modify the forward-link pointer contained in the \a current entry while 00607 * inside the loop, the behavior will be unpredictable. At a minimum, the following 00608 * macros will modify the forward-link pointer, and should not be used inside 00609 * AST_DLLIST_TRAVERSE() against the entry pointed to by the \a current pointer without 00610 * careful consideration of their consequences: 00611 * \li AST_DLLIST_PREV() (when used as an lvalue) 00612 * \li AST_DLLIST_INSERT_BEFORE() 00613 * \li AST_DLLIST_INSERT_HEAD() 00614 * \li AST_DLLIST_INSERT_TAIL() 00615 * \since 1.6.1 00616 */ 00617 #define AST_DLLIST_TRAVERSE_BACKWARDS(head,var,field) \ 00618 AST_DLLIST_TRAVERSE_DIRECTION(head, var, field, last) 00619 00620 #define AST_RWDLLIST_TRAVERSE_BACKWARDS AST_DLLIST_TRAVERSE_BACKWARDS 00621 00622 /*! 00623 * \brief Safe traversal of a doublly linked list using the specified direction list. 00624 * 00625 * \param head List head structure pointer. 00626 * \param var This is the name of the variable that will hold a pointer to the 00627 * current list node on each iteration. It must be declared before calling 00628 * this macro. 00629 * \param field List node field for the next node information. (declared using AST_DLLIST_ENTRY()) 00630 * \param start Specified list node to start traversal: first or last 00631 * 00632 * This macro is used to safely loop over (traverse) the nodes in a list. It 00633 * uses a \a for loop, and supplies the enclosed code with a pointer to each list 00634 * node as it loops. It is typically used as follows: 00635 * 00636 * \code 00637 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00638 * ... 00639 * struct list_entry { 00640 * ... 00641 * AST_DLLIST_ENTRY(list_entry) list; 00642 * } 00643 * ... 00644 * struct list_entry *current; 00645 * ... 00646 * AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN(&entries, current, list, first) { 00647 * (do something with current here (travers list in forward direction)) 00648 * } 00649 * ... 00650 * AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN(&entries, current, list, last) { 00651 * (do something with current here (travers list in reverse direction)) 00652 * } 00653 * AST_DLLIST_TRAVERSE_DIRECTION_SAFE_END; 00654 * \endcode 00655 * 00656 * It differs from AST_DLLIST_TRAVERSE() in that the code inside the loop can modify 00657 * (or even free, after calling AST_DLLIST_REMOVE_CURRENT()) the entry pointed to by 00658 * the \a current pointer without affecting the loop traversal. 00659 * 00660 * \since 11 00661 */ 00662 #define AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN(head, var, field, start) \ 00663 do { \ 00664 typeof((head)) __list_head = (head); \ 00665 typeof(__list_head->first) __list_current; \ 00666 typeof(__list_head->first) __list_first; \ 00667 typeof(__list_head->first) __list_last; \ 00668 typeof(__list_head->first) __list_next; \ 00669 for ((var) = __list_head->start, \ 00670 __list_current = (var), \ 00671 __list_first = (var) ? (var)->field.first : NULL, \ 00672 __list_last = (var) ? (var)->field.last : NULL, \ 00673 __list_next = (var) ? AST_DLLIST_NEXT_DIRECTION(var, field, start) : NULL; \ 00674 (var); \ 00675 (void) __list_current,/* To quiet compiler? */ \ 00676 (void) __list_first,/* To quiet compiler? */ \ 00677 (void) __list_last,/* To quiet compiler? */ \ 00678 (var) = __list_next, \ 00679 __list_current = (var), \ 00680 __list_first = (var) ? (var)->field.first : NULL, \ 00681 __list_last = (var) ? (var)->field.last : NULL, \ 00682 __list_next = (var) ? AST_DLLIST_NEXT_DIRECTION(var, field, start) : NULL \ 00683 ) 00684 00685 #define AST_RWDLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN 00686 00687 /*! 00688 * \brief Inserts a list node before the current node during a traversal. 00689 * \param elm This is a pointer to the entry to be inserted. 00690 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00691 * used to link nodes of this list together. 00692 * 00693 * \since 1.6.1 00694 */ 00695 #define AST_DLLIST_INSERT_BEFORE_CURRENT(elm, field) \ 00696 do { \ 00697 typeof((elm)) __elm = (elm); \ 00698 __elm->field.last = __list_last; \ 00699 __elm->field.first = __list_current; \ 00700 if (__list_head->first == __list_current) { \ 00701 __list_head->first = __elm; \ 00702 } else { \ 00703 __list_last->field.first = __elm; \ 00704 } \ 00705 __list_current->field.last = __elm; \ 00706 if (__list_next == __list_last) { \ 00707 __list_next = __elm; \ 00708 } \ 00709 __list_last = __elm; \ 00710 } while (0) 00711 00712 #define AST_RWDLLIST_INSERT_BEFORE_CURRENT AST_DLLIST_INSERT_BEFORE_CURRENT 00713 00714 /*! 00715 * \brief Inserts a list node after the current node during a traversal. 00716 * \param elm This is a pointer to the node to be inserted. 00717 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00718 * used to link nodes of this list together. 00719 * 00720 * \since 11 00721 */ 00722 #define AST_DLLIST_INSERT_AFTER_CURRENT(elm, field) \ 00723 do { \ 00724 typeof((elm)) __elm = (elm); \ 00725 __elm->field.first = __list_first; \ 00726 __elm->field.last = __list_current; \ 00727 if (__list_head->last == __list_current) { \ 00728 __list_head->last = __elm; \ 00729 } else { \ 00730 __list_first->field.last = __elm; \ 00731 } \ 00732 __list_current->field.first = __elm; \ 00733 if (__list_next == __list_first) { \ 00734 __list_next = __elm; \ 00735 } \ 00736 __list_first = __elm; \ 00737 } while (0) 00738 00739 #define AST_RWDLLIST_INSERT_AFTER_CURRENT AST_DLLIST_INSERT_AFTER_CURRENT 00740 00741 /*! 00742 * \brief Removes the \a current entry from a list during a traversal. 00743 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00744 * used to link entries of this list together. 00745 * 00746 * \note This macro can \b only be used inside an AST_DLLIST_TRAVERSE_SAFE_BEGIN() 00747 * block; it is used to unlink the current entry from the list without affecting 00748 * the list traversal (and without having to re-traverse the list to modify the 00749 * previous entry, if any). 00750 * \since 1.6.1 00751 */ 00752 #define AST_DLLIST_REMOVE_CURRENT(field) \ 00753 do { \ 00754 if (__list_first) { \ 00755 __list_first->field.last = __list_last; \ 00756 } else { \ 00757 __list_head->last = __list_last; \ 00758 } \ 00759 if (__list_last) { \ 00760 __list_last->field.first = __list_first; \ 00761 } else { \ 00762 __list_head->first = __list_first; \ 00763 } \ 00764 __list_current->field.first = NULL; \ 00765 __list_current->field.last = NULL; \ 00766 __list_current = NULL; \ 00767 } while (0) 00768 00769 #define AST_RWDLLIST_REMOVE_CURRENT AST_DLLIST_REMOVE_CURRENT 00770 00771 /*! 00772 * \brief Move the current list entry to another list at the tail. 00773 * 00774 * \note This is a silly macro. It should be done explicitly 00775 * otherwise the field parameter must be the same for the two 00776 * lists. 00777 * 00778 * AST_DLLIST_REMOVE_CURRENT(field); 00779 * AST_DLLIST_INSERT_TAIL(newhead, var, other_field); 00780 */ 00781 #define AST_DLLIST_MOVE_CURRENT(newhead, field) \ 00782 do { \ 00783 typeof ((newhead)->first) __list_cur = __list_current; \ 00784 AST_DLLIST_REMOVE_CURRENT(field); \ 00785 AST_DLLIST_INSERT_TAIL((newhead), __list_cur, field); \ 00786 } while (0) 00787 00788 #define AST_RWDLLIST_MOVE_CURRENT AST_DLLIST_MOVE_CURRENT 00789 00790 /*! 00791 * \brief Move the current list entry to another list at the head. 00792 * 00793 * \note This is a silly macro. It should be done explicitly 00794 * otherwise the field parameter must be the same for the two 00795 * lists. 00796 * 00797 * AST_DLLIST_REMOVE_CURRENT(field); 00798 * AST_DLLIST_INSERT_HEAD(newhead, var, other_field); 00799 */ 00800 #define AST_DLLIST_MOVE_CURRENT_BACKWARDS(newhead, field) \ 00801 do { \ 00802 typeof ((newhead)->first) __list_cur = __list_current; \ 00803 AST_DLLIST_REMOVE_CURRENT(field); \ 00804 AST_DLLIST_INSERT_HEAD((newhead), __list_cur, field); \ 00805 } while (0) 00806 00807 #define AST_RWDLLIST_MOVE_CURRENT_BACKWARDS AST_DLLIST_MOVE_CURRENT_BACKWARDS 00808 00809 #define AST_DLLIST_TRAVERSE_DIRECTION_SAFE_END \ 00810 } while (0) 00811 00812 #define AST_RWDLLIST_TRAVERSE_DIRECTION_SAFE_END AST_DLLIST_TRAVERSE_DIRECTION_SAFE_END 00813 00814 /*! 00815 * \brief Loops safely over (traverses) the entries in a list. 00816 * \param head This is a pointer to the list head structure 00817 * \param var This is the name of the variable that will hold a pointer to the 00818 * current list entry on each iteration. It must be declared before calling 00819 * this macro. 00820 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00821 * used to link entries of this list together. 00822 * 00823 * This macro is used to safely loop over (traverse) the entries in a list. It 00824 * uses a \a for loop, and supplies the enclosed code with a pointer to each list 00825 * entry as it loops. It is typically used as follows: 00826 * 00827 * \code 00828 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00829 * ... 00830 * struct list_entry { 00831 * ... 00832 * AST_DLLIST_ENTRY(list_entry) list; 00833 * } 00834 * ... 00835 * struct list_entry *current; 00836 * ... 00837 * AST_DLLIST_TRAVERSE_SAFE_BEGIN(&entries, current, list) { 00838 * (do something with current here) 00839 * } 00840 * AST_DLLIST_TRAVERSE_SAFE_END; 00841 * \endcode 00842 * 00843 * It differs from AST_DLLIST_TRAVERSE() in that the code inside the loop can modify 00844 * (or even free, after calling AST_DLLIST_REMOVE_CURRENT()) the entry pointed to by 00845 * the \a current pointer without affecting the loop traversal. 00846 * \since 1.6.1 00847 */ 00848 #define AST_DLLIST_TRAVERSE_SAFE_BEGIN(head, var, field) \ 00849 AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN(head, var, field, first) 00850 00851 #define AST_RWDLLIST_TRAVERSE_SAFE_BEGIN AST_DLLIST_TRAVERSE_SAFE_BEGIN 00852 00853 /*! 00854 * \brief Loops safely over (traverses) the entries in a list. 00855 * \param head This is a pointer to the list head structure 00856 * \param var This is the name of the variable that will hold a pointer to the 00857 * current list entry on each iteration. It must be declared before calling 00858 * this macro. 00859 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00860 * used to link entries of this list together. 00861 * 00862 * This macro is used to safely loop over (traverse) the entries in a list. It 00863 * uses a \a for loop, and supplies the enclosed code with a pointer to each list 00864 * entry as it loops. It is typically used as follows: 00865 * 00866 * \code 00867 * static AST_DLLIST_HEAD(entry_list, list_entry) entries; 00868 * ... 00869 * struct list_entry { 00870 * ... 00871 * AST_DLLIST_ENTRY(list_entry) list; 00872 * } 00873 * ... 00874 * struct list_entry *current; 00875 * ... 00876 * AST_DLLIST_TRAVERSE_SAFE_BEGIN(&entries, current, list) { 00877 * (do something with current here) 00878 * } 00879 * AST_DLLIST_TRAVERSE_SAFE_END; 00880 * \endcode 00881 * 00882 * It differs from AST_DLLIST_TRAVERSE() in that the code inside the loop can modify 00883 * (or even free, after calling AST_DLLIST_REMOVE_CURRENT()) the entry pointed to by 00884 * the \a current pointer without affecting the loop traversal. 00885 * \since 1.6.1 00886 */ 00887 #define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(head, var, field) \ 00888 AST_DLLIST_TRAVERSE_DIRECTION_SAFE_BEGIN(head, var, field, last) 00889 00890 #define AST_RWDLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN 00891 00892 /*! 00893 * \brief Inserts a list entry after the current entry during a backwards traversal. Since 00894 * this is a backwards traversal, this will insert the entry AFTER the current 00895 * element. Since this is a backwards traveral, though, this would be BEFORE 00896 * the current entry in traversal order. Confusing? 00897 * \param elm This is a pointer to the entry to be inserted. 00898 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 00899 * used to link entries of this list together. 00900 * 00901 * \since 1.6.1 00902 */ 00903 #define AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS(elm, field) \ 00904 AST_DLLIST_INSERT_AFTER_CURRENT(elm, field) 00905 00906 #define AST_RWDLLIST_INSERT_BEFORE_CURRENT_BACKWARDS AST_DLLIST_INSERT_BEFORE_CURRENT_BACKWARDS 00907 00908 /*! 00909 * \brief Closes a safe loop traversal block. 00910 * \since 1.6.1 00911 */ 00912 #define AST_DLLIST_TRAVERSE_SAFE_END AST_DLLIST_TRAVERSE_DIRECTION_SAFE_END 00913 00914 #define AST_RWDLLIST_TRAVERSE_SAFE_END AST_DLLIST_TRAVERSE_SAFE_END 00915 00916 /*! 00917 * \brief Closes a safe loop traversal block. 00918 * \since 1.6.1 00919 */ 00920 #define AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END AST_DLLIST_TRAVERSE_DIRECTION_SAFE_END 00921 00922 #define AST_RWDLLIST_TRAVERSE_BACKWARDS_SAFE_END AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END 00923 00924 /*! 00925 * \brief Initializes a list head structure. 00926 * \param head This is a pointer to the list head structure 00927 * 00928 * This macro initializes a list head structure by setting the head 00929 * entry to \a NULL (empty list) and recreating the embedded lock. 00930 * \since 1.6.1 00931 */ 00932 #define AST_DLLIST_HEAD_INIT(head) \ 00933 { \ 00934 (head)->first = NULL; \ 00935 (head)->last = NULL; \ 00936 ast_mutex_init(&(head)->lock); \ 00937 } 00938 00939 /*! 00940 * \brief Initializes an rwlist head structure. 00941 * \param head This is a pointer to the list head structure 00942 * 00943 * This macro initializes a list head structure by setting the head 00944 * entry to \a NULL (empty list) and recreating the embedded lock. 00945 * \since 1.6.1 00946 */ 00947 #define AST_RWDLLIST_HEAD_INIT(head) \ 00948 { \ 00949 (head)->first = NULL; \ 00950 (head)->last = NULL; \ 00951 ast_rwlock_init(&(head)->lock); \ 00952 } 00953 00954 /*! 00955 * \brief Destroys a list head structure. 00956 * \param head This is a pointer to the list head structure 00957 * 00958 * This macro destroys a list head structure by setting the head 00959 * entry to \a NULL (empty list) and destroying the embedded lock. 00960 * It does not free the structure from memory. 00961 * \since 1.6.1 00962 */ 00963 #define AST_DLLIST_HEAD_DESTROY(head) \ 00964 { \ 00965 (head)->first = NULL; \ 00966 (head)->last = NULL; \ 00967 ast_mutex_destroy(&(head)->lock); \ 00968 } 00969 00970 /*! 00971 * \brief Destroys an rwlist head structure. 00972 * \param head This is a pointer to the list head structure 00973 * 00974 * This macro destroys a list head structure by setting the head 00975 * entry to \a NULL (empty list) and destroying the embedded lock. 00976 * It does not free the structure from memory. 00977 * \since 1.6.1 00978 */ 00979 #define AST_RWDLLIST_HEAD_DESTROY(head) \ 00980 { \ 00981 (head)->first = NULL; \ 00982 (head)->last = NULL; \ 00983 ast_rwlock_destroy(&(head)->lock); \ 00984 } 00985 00986 /*! 00987 * \brief Initializes a list head structure. 00988 * \param head This is a pointer to the list head structure 00989 * 00990 * This macro initializes a list head structure by setting the head 00991 * entry to \a NULL (empty list). There is no embedded lock handling 00992 * with this macro. 00993 * \since 1.6.1 00994 */ 00995 #define AST_DLLIST_HEAD_INIT_NOLOCK(head) \ 00996 { \ 00997 (head)->first = NULL; \ 00998 (head)->last = NULL; \ 00999 } 01000 01001 /*! 01002 * \brief Inserts a list entry after a given entry. 01003 * \param head This is a pointer to the list head structure 01004 * \param listelm This is a pointer to the entry after which the new entry should 01005 * be inserted. 01006 * \param elm This is a pointer to the entry to be inserted. 01007 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01008 * used to link entries of this list together. 01009 * \since 1.6.1 01010 */ 01011 #define AST_DLLIST_INSERT_AFTER(head, listelm, elm, field) \ 01012 do { \ 01013 typeof((listelm)) __listelm = (listelm); \ 01014 typeof((elm)) __elm = (elm); \ 01015 __elm->field.first = __listelm->field.first; \ 01016 __elm->field.last = __listelm; \ 01017 if ((head)->last == __listelm) { \ 01018 (head)->last = __elm; \ 01019 } else { \ 01020 __listelm->field.first->field.last = __elm; \ 01021 } \ 01022 __listelm->field.first = __elm; \ 01023 } while (0) 01024 01025 #define AST_RWDLLIST_INSERT_AFTER AST_DLLIST_INSERT_AFTER 01026 01027 /*! 01028 * \brief Inserts a list entry before a given entry. 01029 * \param head This is a pointer to the list head structure 01030 * \param listelm This is a pointer to the entry before which the new entry should 01031 * be inserted. 01032 * \param elm This is a pointer to the entry to be inserted. 01033 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01034 * used to link entries of this list together. 01035 * \since 1.6.1 01036 */ 01037 #define AST_DLLIST_INSERT_BEFORE(head, listelm, elm, field) \ 01038 do { \ 01039 typeof((listelm)) __listelm = (listelm); \ 01040 typeof((elm)) __elm = (elm); \ 01041 __elm->field.last = __listelm->field.last; \ 01042 __elm->field.first = __listelm; \ 01043 if ((head)->first == __listelm) { \ 01044 (head)->first = __elm; \ 01045 } else { \ 01046 __listelm->field.last->field.first = __elm; \ 01047 } \ 01048 __listelm->field.last = __elm; \ 01049 } while (0) 01050 01051 #define AST_RWDLLIST_INSERT_BEFORE AST_DLLIST_INSERT_BEFORE 01052 01053 /*! 01054 * \brief Inserts a list entry at the head of a list. 01055 * \param head This is a pointer to the list head structure 01056 * \param elm This is a pointer to the entry to be inserted. 01057 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01058 * used to link entries of this list together. 01059 * \since 1.6.1 01060 */ 01061 #define AST_DLLIST_INSERT_HEAD(head, elm, field) \ 01062 do { \ 01063 typeof((elm)) __elm = (elm); \ 01064 __elm->field.last = NULL; \ 01065 __elm->field.first = (head)->first; \ 01066 if (!(head)->first) { \ 01067 (head)->last = __elm; \ 01068 } else { \ 01069 (head)->first->field.last = __elm; \ 01070 } \ 01071 (head)->first = __elm; \ 01072 } while (0) 01073 01074 #define AST_RWDLLIST_INSERT_HEAD AST_DLLIST_INSERT_HEAD 01075 01076 /*! 01077 * \brief Appends a list entry to the tail of a list. 01078 * \param head This is a pointer to the list head structure 01079 * \param elm This is a pointer to the entry to be appended. 01080 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01081 * used to link entries of this list together. 01082 * 01083 * Note: The link field in the appended entry is \b not modified, so if it is 01084 * actually the head of a list itself, the entire list will be appended 01085 * temporarily (until the next AST_DLLIST_INSERT_TAIL is performed). 01086 * \since 1.6.1 01087 */ 01088 #define AST_DLLIST_INSERT_TAIL(head, elm, field) \ 01089 do { \ 01090 typeof((elm)) __elm = (elm); \ 01091 __elm->field.first = NULL; \ 01092 if (!(head)->first) { \ 01093 __elm->field.last = NULL; \ 01094 (head)->first = __elm; \ 01095 } else { \ 01096 __elm->field.last = (head)->last; \ 01097 (head)->last->field.first = __elm; \ 01098 } \ 01099 (head)->last = __elm; \ 01100 } while (0) 01101 01102 #define AST_RWDLLIST_INSERT_TAIL AST_DLLIST_INSERT_TAIL 01103 01104 /*! 01105 * \brief Appends a whole list to the tail of a list. 01106 * \param head This is a pointer to the list head structure 01107 * \param list This is a pointer to the list to be appended. 01108 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01109 * used to link entries of this list together. 01110 * 01111 * Note: The source list (the \a list parameter) will be empty after 01112 * calling this macro (the list entries are \b moved to the target list). 01113 * \since 1.6.1 01114 */ 01115 #define AST_DLLIST_APPEND_DLLIST(head, list, field) \ 01116 do { \ 01117 if (!(head)->first) { \ 01118 (head)->first = (list)->first; \ 01119 (head)->last = (list)->last; \ 01120 } else { \ 01121 (head)->last->field.first = (list)->first; \ 01122 (list)->first->field.last = (head)->last; \ 01123 (head)->last = (list)->last; \ 01124 } \ 01125 (list)->first = NULL; \ 01126 (list)->last = NULL; \ 01127 } while (0) 01128 01129 #define AST_RWDLLIST_APPEND_DLLIST AST_DLLIST_APPEND_DLLIST 01130 01131 /*! 01132 * \brief Removes and returns the head entry from a list. 01133 * \param head This is a pointer to the list head structure 01134 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01135 * used to link entries of this list together. 01136 * 01137 * Removes the head entry from the list, and returns a pointer to it. 01138 * This macro is safe to call on an empty list. 01139 * \since 1.6.1 01140 */ 01141 #define AST_DLLIST_REMOVE_HEAD(head, field) \ 01142 ({ \ 01143 typeof((head)->first) cur = (head)->first; \ 01144 if (cur) { \ 01145 (head)->first = cur->field.first; \ 01146 if ((head)->first) { \ 01147 (head)->first->field.last = NULL; \ 01148 } \ 01149 cur->field.first = NULL; \ 01150 cur->field.last = NULL; \ 01151 if ((head)->last == cur) { \ 01152 (head)->last = NULL; \ 01153 } \ 01154 } \ 01155 cur; \ 01156 }) 01157 01158 #define AST_RWDLLIST_REMOVE_HEAD AST_DLLIST_REMOVE_HEAD 01159 01160 /*! 01161 * \brief Removes and returns the tail node from a list. 01162 * \param head This is a pointer to the list head structure 01163 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01164 * used to link nodes of this list together. 01165 * 01166 * Removes the tail entry from the list, and returns a pointer to it. 01167 * This macro is safe to call on an empty list. 01168 * \since 11 01169 */ 01170 #define AST_DLLIST_REMOVE_TAIL(head, field) \ 01171 ({ \ 01172 typeof((head)->last) cur = (head)->last; \ 01173 if (cur) { \ 01174 (head)->last = cur->field.last; \ 01175 if ((head)->last) { \ 01176 (head)->last->field.first = NULL; \ 01177 } \ 01178 cur->field.first = NULL; \ 01179 cur->field.last = NULL; \ 01180 if ((head)->first == cur) { \ 01181 (head)->first = NULL; \ 01182 } \ 01183 } \ 01184 cur; \ 01185 }) 01186 01187 #define AST_RWDLLIST_REMOVE_TAIL AST_DLLIST_REMOVE_TAIL 01188 01189 /*! 01190 * \brief Removes a specific entry from a list. 01191 * \param head This is a pointer to the list head structure 01192 * \param elm This is a pointer to the entry to be removed. 01193 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01194 * used to link entries of this list together. 01195 * \warning The removed entry is \b not freed. 01196 * \since 1.6.1 01197 */ 01198 #define AST_DLLIST_REMOVE(head, elm, field) \ 01199 do { \ 01200 typeof((elm)) __elm = (elm); \ 01201 if (__elm) { \ 01202 if (__elm->field.first) { \ 01203 __elm->field.first->field.last = __elm->field.last; \ 01204 } else { \ 01205 (head)->last = __elm->field.last; \ 01206 } \ 01207 if (__elm->field.last) { \ 01208 __elm->field.last->field.first = __elm->field.first; \ 01209 } else { \ 01210 (head)->first = __elm->field.first; \ 01211 } \ 01212 __elm->field.first = NULL; \ 01213 __elm->field.last = NULL; \ 01214 } \ 01215 } while (0) 01216 01217 #define AST_RWDLLIST_REMOVE AST_DLLIST_REMOVE 01218 01219 /*! 01220 * \brief Removes a specific node from a list if it is in the list. 01221 * \param head This is a pointer to the list head structure 01222 * \param elm This is a pointer to the node to be removed. 01223 * \param field This is the name of the field (declared using AST_DLLIST_ENTRY()) 01224 * used to link nodes of this list together. 01225 * \warning The removed node is \b not freed. 01226 * \return elm if the list had elm in it. 01227 * \return NULL if not. 01228 * \since 11 01229 */ 01230 #define AST_DLLIST_REMOVE_VERIFY(head, elm, field) \ 01231 ({ \ 01232 typeof((elm)) __res = AST_DLLIST_IS_MEMBER(head, elm, field); \ 01233 AST_DLLIST_REMOVE(head, __res, field); \ 01234 __res; \ 01235 }) 01236 01237 #define AST_RWDLLIST_REMOVE_VERIFY AST_DLLIST_REMOVE_VERIFY 01238 01239 #endif /* _ASTERISK_DLINKEDLISTS_H */