improve linked-list macros in two ways:
authorKevin P. Fleming <kpfleming@digium.com>
Thu, 8 Nov 2007 05:28:47 +0000 (05:28 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Thu, 8 Nov 2007 05:28:47 +0000 (05:28 +0000)
  - 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: https://origsvn.digium.com/svn/asterisk/trunk@89106 65c4cc65-6c06-0410-ace0-fbb531ad65f3

41 files changed:
apps/app_followme.c
apps/app_meetme.c
apps/app_queue.c
apps/app_voicemail.c
channels/chan_agent.c
channels/chan_iax2.c
channels/iax2-parser.c
codecs/codec_zap.c
funcs/func_strings.c
include/asterisk/linkedlists.h
main/app.c
main/asterisk.c
main/astobj2.c
main/audiohook.c
main/autoservice.c
main/cdr.c
main/channel.c
main/cli.c
main/config.c
main/devicestate.c
main/event.c
main/file.c
main/frame.c
main/image.c
main/indications.c
main/loader.c
main/logger.c
main/manager.c
main/pbx.c
main/sched.c
main/srv.c
main/translate.c
pbx/pbx_dundi.c
res/res_agi.c
res/res_crypto.c
res/res_features.c
res/res_jabber.c
res/res_musiconhold.c
res/res_odbc.c
res/res_speech.c
utils/astman.c

index 0624157..c5a5723 100644 (file)
@@ -840,13 +840,12 @@ static void findmeexec(struct fm_args *tpargs)
                        winner = wait_for_winner(findme_user_list, nm, caller, tpargs->namerecloc, &status, tpargs);
                
                                        
-               AST_LIST_TRAVERSE_SAFE_BEGIN(findme_user_list, fmuser, entry) {
+               while ((fmuser = AST_LIST_REMOVE_HEAD(findme_user_list, entry))) {
                        if (!fmuser->cleared && fmuser->ochan != winner)
                                clear_caller(fmuser);
-                       AST_LIST_REMOVE_CURRENT(findme_user_list, entry);
                        ast_free(fmuser);
                }
-               AST_LIST_TRAVERSE_SAFE_END
+
                fmuser = NULL;
                tmpuser = NULL;
                headuser = NULL;        
@@ -978,11 +977,8 @@ static int app_exec(struct ast_channel *chan, void *data)
        
        findmeexec(&targs);             
        
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&targs.cnumbers, nm, entry) {
-               AST_LIST_REMOVE_CURRENT(&targs.cnumbers, entry);
+       while ((nm = AST_LIST_REMOVE_HEAD(&targs.cnumbers, entry)))
                ast_free(nm);
-       }
-       AST_LIST_TRAVERSE_SAFE_END
                
        if (!ast_strlen_zero(namerecloc))
                unlink(namerecloc);     
index 48014ed..4cebb63 100644 (file)
@@ -3971,14 +3971,14 @@ static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *st
                                continue;
 
                        if (remove)
-                               AST_LIST_REMOVE_CURRENT(&sla.ringing_trunks, entry);
+                               AST_LIST_REMOVE_CURRENT(entry);
 
                        if (trunk_ref)
                                *trunk_ref = s_trunk_ref;
 
                        break;
                }
-               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_TRAVERSE_SAFE_END;
        
                if (ringing_trunk)
                        break;
@@ -4006,11 +4006,11 @@ static void sla_handle_dial_state_event(void)
                case AST_DIAL_RESULT_FAILED:
                case AST_DIAL_RESULT_TIMEOUT:
                case AST_DIAL_RESULT_UNANSWERED:
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_NORMAL);
                        break;
                case AST_DIAL_RESULT_ANSWERED:
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        /* Find the appropriate trunk to answer. */
                        ast_mutex_lock(&sla.lock);
                        ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
@@ -4055,7 +4055,7 @@ static void sla_handle_dial_state_event(void)
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 }
 
 /*! \brief Check to see if this station is already ringing 
@@ -4085,7 +4085,7 @@ static int sla_check_failed_station(const struct sla_station *station)
                if (station != failed_station->station)
                        continue;
                if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
-                       AST_LIST_REMOVE_CURRENT(&sla.failed_stations, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        ast_free(failed_station);
                        break;
                }
@@ -4284,7 +4284,7 @@ static void sla_hangup_stations(void)
                                break;
                }
                if (!trunk_ref) {
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        ast_dial_join(ringing_station->station->dial);
                        ast_dial_destroy(ringing_station->station->dial);
                        ringing_station->station->dial = NULL;
@@ -4341,7 +4341,7 @@ static int sla_calc_trunk_timeouts(unsigned int *timeout)
                time_left = (ringing_trunk->trunk->ring_timeout * 1000) - time_elapsed;
                if (time_left <= 0) {
                        pbx_builtin_setvar_helper(ringing_trunk->trunk->chan, "SLATRUNK_STATUS", "RINGTIMEOUT");
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_trunks, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        sla_stop_ringing_trunk(ringing_trunk);
                        res = 1;
                        continue;
@@ -4349,7 +4349,7 @@ static int sla_calc_trunk_timeouts(unsigned int *timeout)
                if (time_left < *timeout)
                        *timeout = time_left;
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        return res;
 }
@@ -4422,7 +4422,7 @@ static int sla_calc_station_timeouts(unsigned int *timeout)
 
                /* If there is no time left, the station needs to stop ringing */
                if (time_left <= 0) {
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_TIMEOUT);
                        res = 1;
                        continue;
@@ -4433,7 +4433,7 @@ static int sla_calc_station_timeouts(unsigned int *timeout)
                if (time_left < *timeout)
                        *timeout = time_left;
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        return res;
 }
@@ -4992,11 +4992,11 @@ static int sla_trunk_exec(struct ast_channel *chan, void *data)
        ast_mutex_lock(&sla.lock);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
                if (ringing_trunk->trunk == trunk) {
-                       AST_LIST_REMOVE_CURRENT(&sla.ringing_trunks, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        ast_mutex_unlock(&sla.lock);
        if (ringing_trunk) {
                sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
index 9b6ed81..9042149 100644 (file)
@@ -933,7 +933,7 @@ static int remove_from_interfaces(const char *interface)
                if (!strcasecmp(curint->interface, interface)) {
                        if (!interface_exists_global(interface)) {
                                ast_debug(1, "Removing %s from the list of interfaces that make up all of our queue members.\n", interface);
-                               AST_LIST_REMOVE_CURRENT(&interfaces, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                ast_free(curint);
                        }
                        break;
index 0d98b18..1be9874 100644 (file)
@@ -4381,7 +4381,7 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
                                copy_message(chan, sender, 0, curmsg, duration, vmtmp, fmt, dir);
 #endif
                                saved_messages++;
-                               AST_LIST_REMOVE_CURRENT(&extensions, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                free_user(vmtmp);
                                if (res)
                                        break;
@@ -7804,7 +7804,7 @@ static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
        AST_RWLIST_WRLOCK(&mwi_subs);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&mwi_subs, mwi_sub, entry) {
                if (mwi_sub->uniqueid == uniqueid) {
-                       AST_LIST_REMOVE_CURRENT(&mwi_subs, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        break;
                }
        }
index 70c2b9d..342f467 100644 (file)
@@ -1152,7 +1152,7 @@ static int read_agent_config(int reload)
        }
        AST_LIST_TRAVERSE_SAFE_BEGIN(&agents, p, list) {
                if (p->dead) {
-                       AST_LIST_REMOVE_CURRENT(&agents, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        /* Destroy if  appropriate */
                        if (!p->owner) {
                                if (!p->chan) {
@@ -1166,7 +1166,7 @@ static int read_agent_config(int reload)
                        }
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&agents);
        ast_config_destroy(cfg);
        return 1;
index dded091..0e3a8f7 100644 (file)
@@ -1918,10 +1918,10 @@ static void reload_firmware(int unload)
        AST_LIST_TRAVERSE_SAFE_BEGIN(&firmwares, cur, list) {
                if (!cur->dead)
                        continue;
-               AST_LIST_REMOVE_CURRENT(&firmwares, list);
+               AST_LIST_REMOVE_CURRENT(list);
                destroy_firmware(cur);
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        AST_LIST_UNLOCK(&firmwares);
 }
@@ -6127,7 +6127,7 @@ static int complete_dpreply(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
        AST_LIST_TRAVERSE_SAFE_BEGIN(&dpcache, dp, peer_list) {
                if (strcmp(dp->exten, exten))
                        continue;
-               AST_LIST_REMOVE_CURRENT(&dpcache, peer_list);
+               AST_LIST_REMOVE_CURRENT(peer_list);
                dp->callno = 0;
                dp->expiry.tv_sec = dp->orig.tv_sec + expiry;
                if (dp->flags & CACHE_FLAG_PENDING) {
@@ -6140,7 +6140,7 @@ static int complete_dpreply(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
                        if (dp->waiters[x] > -1)
                                write(dp->waiters[x], "asdf", 4);
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&dpcache);
 
        return 0;
@@ -6908,7 +6908,7 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
                if (!drop && iax2_trunk_expired(tpeer, &now)) {
                        /* Take it out of the list, but don't free it yet, because it
                           could be in use */
-                       AST_LIST_REMOVE_CURRENT(&tpeers, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        drop = tpeer;
                } else {
                        res = send_trunk(tpeer, &now);
@@ -6920,7 +6920,7 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
                res = 0;
                ast_mutex_unlock(&tpeer->lock);
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&tpeers);
 
        if (drop) {
@@ -7209,7 +7209,7 @@ static void defer_full_frame(struct iax2_thread *from_here, struct iax2_thread *
        AST_LIST_TRAVERSE_SAFE_BEGIN(&to_here->full_frames, cur_pkt_buf, entry) {
                cur_fh = (struct ast_iax2_full_hdr *) cur_pkt_buf->buf;
                if (fh->oseqno < cur_fh->oseqno) {
-                       AST_LIST_INSERT_BEFORE_CURRENT(&to_here->full_frames, pkt_buf, entry);
+                       AST_LIST_INSERT_BEFORE_CURRENT(pkt_buf, entry);
                        break;
                }
        }
@@ -7478,12 +7478,12 @@ static int acf_iaxvar_write(struct ast_channel *chan, const char *cmd, char *dat
        AST_LIST_LOCK(varlist);
        AST_LIST_TRAVERSE_SAFE_BEGIN(varlist, var, entries) {
                if (strcmp(var->name, data) == 0) {
-                       AST_LIST_REMOVE_CURRENT(varlist, entries);
+                       AST_LIST_REMOVE_CURRENT(entries);
                        ast_var_delete(var);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        var = ast_var_assign(data, value);
        if (var)
                AST_LIST_INSERT_TAIL(varlist, var, entries);
@@ -9538,7 +9538,7 @@ static void *network_thread(void *ignore)
 
                        if (f->retries < 0) {
                                /* This is not supposed to be retransmitted */
-                               AST_LIST_REMOVE_CURRENT(&frame_queue, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                /* Free the iax frame */
                                iax_frame_free(f);
                        } else {
@@ -9547,7 +9547,7 @@ static void *network_thread(void *ignore)
                                f->retrans = iax2_sched_add(sched, f->retrytime, attempt_transmit, f);
                        }
                }
-               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_TRAVERSE_SAFE_END;
                AST_LIST_UNLOCK(&frame_queue);
 
                pthread_testcancel();
@@ -10832,7 +10832,7 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
 
        AST_LIST_TRAVERSE_SAFE_BEGIN(&dpcache, dp, cache_list) {
                if (ast_tvcmp(tv, dp->expiry) > 0) {
-                       AST_LIST_REMOVE_CURRENT(&dpcache, cache_list);
+                       AST_LIST_REMOVE_CURRENT(cache_list);
                        if ((dp->flags & CACHE_FLAG_PENDING) || dp->callno)
                                ast_log(LOG_WARNING, "DP still has peer field or pending or callno (flags = %d, peer = blah, callno = %d)\n", dp->flags, dp->callno);
                        else
@@ -10842,7 +10842,7 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
                if (!strcmp(dp->peercontext, data) && !strcmp(dp->exten, exten))
                        break;
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        if (!dp) {
                /* No matching entry.  Create a new one. */
@@ -11420,27 +11420,18 @@ static int __unload_module(void)
 
        /* Call for all threads to halt */
        AST_LIST_LOCK(&idle_list);
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&idle_list, thread, list) {
-               AST_LIST_REMOVE_CURRENT(&idle_list, list);
+       while ((thread = AST_LIST_REMOVE_HEAD(&idle_list, list)))
                pthread_cancel(thread->threadid);
-       }
-       AST_LIST_TRAVERSE_SAFE_END
-                       AST_LIST_UNLOCK(&idle_list);
+       AST_LIST_UNLOCK(&idle_list);
 
        AST_LIST_LOCK(&active_list);
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&active_list, thread, list) {
-               AST_LIST_REMOVE_CURRENT(&active_list, list);
+       while ((thread = AST_LIST_REMOVE_HEAD(&active_list, list)))
                pthread_cancel(thread->threadid);
-       }
-       AST_LIST_TRAVERSE_SAFE_END
-                       AST_LIST_UNLOCK(&active_list);
+       AST_LIST_UNLOCK(&active_list);
 
        AST_LIST_LOCK(&dynamic_list);
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&dynamic_list, thread, list) {
-               AST_LIST_REMOVE_CURRENT(&dynamic_list, list);
+       while ((thread = AST_LIST_REMOVE_HEAD(&dynamic_list, list)))
                pthread_cancel(thread->threadid);
-       }
-       AST_LIST_TRAVERSE_SAFE_END
        AST_LIST_UNLOCK(&dynamic_list);
        
        /* Wait for threads to exit */
index 0422ab6..a2ec425 100644 (file)
@@ -1003,13 +1003,13 @@ struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheab
                AST_LIST_TRAVERSE_SAFE_BEGIN(iax_frames, fr, list) {
                        if (fr->afdatalen >= datalen) {
                                size_t afdatalen = fr->afdatalen;
-                               AST_LIST_REMOVE_CURRENT(iax_frames, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                memset(fr, 0, sizeof(*fr));
                                fr->afdatalen = afdatalen;
                                break;
                        }
                }
-               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_TRAVERSE_SAFE_END;
        }
        if (!fr) {
                if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
index c38aa5a..11e1860 100644 (file)
@@ -356,7 +356,7 @@ static void drop_translator(int dst, int src)
                if (cur->t.dstfmt != dst)
                        continue;
 
-               AST_LIST_REMOVE_CURRENT(&translators, entry);
+               AST_LIST_REMOVE_CURRENT(entry);
                ast_unregister_translator(&cur->t);
                ast_free(cur);
                global_format_map.map[dst][src] = 0;
index 0ed4bc1..70ecc4c 100644 (file)
@@ -230,7 +230,7 @@ static void clearvar_prefix(struct ast_channel *chan, const char *prefix)
        int len = strlen(prefix);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->varshead, var, entries) {
                if (strncasecmp(prefix, ast_var_name(var), len) == 0) {
-                       AST_LIST_REMOVE_CURRENT(&chan->varshead, entries);
+                       AST_LIST_REMOVE_CURRENT(entries);
                        ast_free(var);
                }
        }
index 21e3876..1f3285d 100644 (file)
@@ -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)
index f08c839..f21a40e 100644 (file)
@@ -873,12 +873,12 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
        AST_RWLIST_WRLOCK(&groups);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
                if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
-                       AST_RWLIST_REMOVE_CURRENT(&groups, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        free(gi);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        if (ast_strlen_zero(group)) {
                /* Enable unsetting the group */
@@ -964,11 +964,11 @@ int ast_app_group_discard(struct ast_channel *chan)
        AST_RWLIST_WRLOCK(&groups);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
                if (gi->chan == chan) {
-                       AST_RWLIST_REMOVE_CURRENT(&groups, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(gi);
                }
        }
-        AST_RWLIST_TRAVERSE_SAFE_END
+        AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&groups);
        
        return 0;
@@ -1204,7 +1204,7 @@ static int ast_unlock_path_flock(const char *path)
        AST_LIST_LOCK(&path_lock_list);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) {
                if (!strcmp(p->path, path)) {
-                       AST_LIST_REMOVE_CURRENT(&path_lock_list, le);
+                       AST_LIST_REMOVE_CURRENT(le);
                        break;
                }
        }
index 61c4ea5..7ba3062 100644 (file)
@@ -286,7 +286,7 @@ void ast_unregister_file_version(const char *file)
        AST_RWLIST_WRLOCK(&file_versions);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
                if (!strcasecmp(find->file, file)) {
-                       AST_RWLIST_REMOVE_CURRENT(&file_versions, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        break;
                }
        }
@@ -325,7 +325,7 @@ void ast_unregister_thread(void *id)
        AST_RWLIST_WRLOCK(&thread_list);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
                if ((void *) x->id == id) {
-                       AST_RWLIST_REMOVE_CURRENT(&thread_list, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        break;
                }
        }
@@ -747,11 +747,11 @@ void ast_unregister_atexit(void (*func)(void))
        AST_RWLIST_WRLOCK(&atexits);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
                if (ae->func == func) {
-                       AST_RWLIST_REMOVE_CURRENT(&atexits, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&atexits);
 
        if (ae)
index c9c4680..8404f03 100644 (file)
@@ -467,7 +467,7 @@ void *ao2_callback(struct ao2_container *c,
 
                                /* we are going to modify the container, so update version */
                                ast_atomic_fetchadd_int(&c->version, 1);
-                               AST_LIST_REMOVE_CURRENT(&c->buckets[i], entry);
+                               AST_LIST_REMOVE_CURRENT(entry);
                                /* update number of elements and version */
                                ast_atomic_fetchadd_int(&c->elements, -1);
                                ao2_ref(EXTERNAL_OBJ(x->astobj), -1);
@@ -488,7 +488,7 @@ void *ao2_callback(struct ao2_container *c,
 #endif
                        }
                }
-               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_TRAVERSE_SAFE_END;
        }
        ao2_unlock(c);
        return ret;
index d1dc6d0..4b7eacb 100644 (file)
@@ -346,35 +346,29 @@ int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
        struct ast_audiohook *audiohook = NULL;
 
        /* Drop any spies */
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
+       while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
                ast_audiohook_lock(audiohook);
-               AST_LIST_REMOVE_CURRENT(&audiohook_list->spy_list, list);
                audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                ast_cond_signal(&audiohook->trigger);
                ast_audiohook_unlock(audiohook);
        }
-       AST_LIST_TRAVERSE_SAFE_END
 
        /* Drop any whispering sources */
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
+       while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
                ast_audiohook_lock(audiohook);
-               AST_LIST_REMOVE_CURRENT(&audiohook_list->whisper_list, list);
                audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                ast_cond_signal(&audiohook->trigger);
                ast_audiohook_unlock(audiohook);
        }
-       AST_LIST_TRAVERSE_SAFE_END
 
        /* Drop any manipulaters */
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
+       while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
                ast_audiohook_lock(audiohook);
                ast_mutex_lock(&audiohook->lock);
-               AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
                audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                ast_audiohook_unlock(audiohook);
                audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
        }
-       AST_LIST_TRAVERSE_SAFE_END
 
        /* Drop translation paths if present */
        for (i = 0; i < 2; i++) {
@@ -453,7 +447,7 @@ static struct ast_frame *dtmf_audiohook_write_list(struct ast_channel *chan, str
        AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
                ast_audiohook_lock(audiohook);
                if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
-                       AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                        ast_audiohook_unlock(audiohook);
                        audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
@@ -463,7 +457,7 @@ static struct ast_frame *dtmf_audiohook_write_list(struct ast_channel *chan, str
                        audiohook->manipulate_callback(audiohook, chan, frame, direction);
                ast_audiohook_unlock(audiohook);
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        return frame;
 }
@@ -500,7 +494,7 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st
        AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
                ast_audiohook_lock(audiohook);
                if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
-                       AST_LIST_REMOVE_CURRENT(&audiohook_list->spy_list, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                        ast_cond_signal(&audiohook->trigger);
                        ast_audiohook_unlock(audiohook);
@@ -519,7 +513,7 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st
                AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
                        ast_audiohook_lock(audiohook);
                        if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
-                               AST_LIST_REMOVE_CURRENT(&audiohook_list->whisper_list, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                                ast_cond_signal(&audiohook->trigger);
                                ast_audiohook_unlock(audiohook);
@@ -544,7 +538,7 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st
                AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
                        ast_audiohook_lock(audiohook);
                        if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
-                               AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
                                ast_audiohook_unlock(audiohook);
                                /* We basically drop all of our links to the manipulate audiohook and prod it to do it's own destructive things */
index 9f175bc..7ef5c0a 100644 (file)
@@ -135,14 +135,14 @@ int ast_autoservice_stop(struct ast_channel *chan)
        AST_RWLIST_WRLOCK(&aslist);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) {     
                if (as->chan == chan) {
-                       AST_RWLIST_REMOVE_CURRENT(&aslist, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(as);
                        if (!ast_check_hangup(chan))
                                res = 0;
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        if (asthread != AST_PTHREADT_NULL) 
                pthread_kill(asthread, SIGURG);
index b4a185c..166cfae 100644 (file)
@@ -151,7 +151,7 @@ void ast_cdr_unregister(const char *name)
        AST_RWLIST_WRLOCK(&be_list);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
                if (!strcasecmp(name, i->name)) {
-                       AST_RWLIST_REMOVE_CURRENT(&be_list, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_verb(2, "Unregistered '%s' CDR backend\n", name);
                        ast_free(i);
                        break;
@@ -313,7 +313,7 @@ int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int
                        AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
                                if (!strcasecmp(ast_var_name(newvariable), name)) {
                                        /* there is already such a variable, delete it */
-                                       AST_LIST_REMOVE_CURRENT(headp, entries);
+                                       AST_LIST_REMOVE_CURRENT(entries);
                                        ast_var_delete(newvariable);
                                        break;
                                }
@@ -491,9 +491,8 @@ static void cdr_merge_vars(struct ast_cdr *to, struct ast_cdr *from)
                } else if (tovarname && strcasecmp(fromvarval,tovarval) == 0) /* if they are the same, the job is done */
                        continue;
 
-               /*rip this var out of the from cdr, and stick it in the to cdr */
-               AST_LIST_REMOVE_CURRENT(headpfrom, entries);
-               AST_LIST_INSERT_HEAD(headpto, variablesfrom, entries);
+               /* rip this var out of the from cdr, and stick it in the to cdr */
+               AST_LIST_MOVE_CURRENT(headpto, entries);
        }
        AST_LIST_TRAVERSE_SAFE_END;
 }
index b2f993d..a0769fa 100644 (file)
@@ -451,13 +451,13 @@ void ast_channel_unregister(const struct ast_channel_tech *tech)
 
        AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
                if (chan->tech == tech) {
-                       AST_LIST_REMOVE_CURRENT(&backends, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        ast_free(chan);
                        ast_verb(2, "Unregistered channel type '%s'\n", tech->type);
                        break;  
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        AST_RWLIST_UNLOCK(&channels);
 }
@@ -1256,12 +1256,12 @@ int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore
        /* Find our position and remove ourselves */
        AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore2, entry) {
                if (datastore2 == datastore) {
-                       AST_LIST_REMOVE_CURRENT(&chan->datastores, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        res = 0;
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        return res;
 }
index 2277dca..2cb85e4 100644 (file)
@@ -1420,7 +1420,7 @@ static int __ast_cli_register(struct ast_cli_entry *e, struct ast_cli_entry *ed)
                if (lf < len)
                        len = lf;
                if (strncasecmp(e->_full_cmd, cur->_full_cmd, len) < 0) {
-                       AST_RWLIST_INSERT_BEFORE_CURRENT(&helpers, e, list); 
+                       AST_RWLIST_INSERT_BEFORE_CURRENT(e, list); 
                        break;
                }
        }
index 736c542..59b1840 100644 (file)
@@ -545,11 +545,9 @@ static void ast_destroy_comments(struct ast_category *cat)
 static void ast_destroy_template_list(struct ast_category *cat)
 {
        struct ast_category_template_instance *x;
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&cat->template_instances, x, next) {
-               AST_LIST_REMOVE_CURRENT(&cat->template_instances, next);
+
+       while ((x = AST_LIST_REMOVE_HEAD(&cat->template_instances, next)))
                free(x);
-       }
-       AST_LIST_TRAVERSE_SAFE_END;
 }
 
 void ast_category_destroy(struct ast_category *cat)
index aef21f7..c36fa69 100644 (file)
@@ -372,7 +372,7 @@ int ast_devstate_prov_del(const char *label)
        AST_RWLIST_WRLOCK(&devstate_provs);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
                if (!strcasecmp(devcb->label, label)) {
-                       AST_RWLIST_REMOVE_CURRENT(&devstate_provs, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(devcb);
                        res = 0;
                        break;
index 45d5823..23b16e5 100644 (file)
@@ -708,11 +708,11 @@ int ast_event_queue_and_cache(struct ast_event *event, ...)
                }
                if (!cache_arg) {
                        /* All parameters were matched on this cache entry, so remove it */
-                       AST_LIST_REMOVE_CURRENT(&ast_event_cache[host_event_type], entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        ast_event_ref_destroy(event_ref);
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        res = ast_event_dup_and_cache(event);
        AST_RWLIST_UNLOCK(&ast_event_cache[host_event_type]);
 
index 3fb5fa8..de69ab0 100644 (file)
@@ -110,12 +110,12 @@ int ast_format_unregister(const char *name)
        AST_RWLIST_WRLOCK(&formats);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
                if (!strcasecmp(name, tmp->name)) {
-                       AST_RWLIST_REMOVE_CURRENT(&formats, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(tmp);
                        res = 0;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&formats);
 
        if (!res)
index a0109fd..50e9dab 100644 (file)
@@ -452,7 +452,8 @@ struct ast_frame *ast_frdup(const struct ast_frame *f)
                AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
                        if (out->mallocd_hdr_len >= len) {
                                size_t mallocd_len = out->mallocd_hdr_len;
-                               AST_LIST_REMOVE_CURRENT(&frames->list, frame_list);
+
+                               AST_LIST_REMOVE_CURRENT(frame_list);
                                memset(out, 0, sizeof(*out));
                                out->mallocd_hdr_len = mallocd_len;
                                buf = out;
@@ -460,7 +461,7 @@ struct ast_frame *ast_frdup(const struct ast_frame *f)
                                break;
                        }
                }
-               AST_LIST_TRAVERSE_SAFE_END
+               AST_LIST_TRAVERSE_SAFE_END;
        }
 #endif
 
index 5e6ce55..91cdeba 100644 (file)
@@ -65,11 +65,11 @@ void ast_image_unregister(struct ast_imager *img)
        AST_RWLIST_WRLOCK(&imagers);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {     
                if (i == img) {
-                       AST_RWLIST_REMOVE_CURRENT(&imagers, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&imagers);
        if (i)
                ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc);
index 61f3328..ebebc68 100644 (file)
@@ -480,12 +480,12 @@ int ast_register_indication_country(struct ind_tone_zone *zone)
                if (tz == current_tonezone)
                        current_tonezone = zone;
                /* Remove from the linked list */
-               AST_RWLIST_REMOVE_CURRENT(&tone_zones, list);
+               AST_RWLIST_REMOVE_CURRENT(list);
                /* Finally free the zone itself */
                free_zone(tz);
                break;
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        /* Add zone to the list */
        AST_RWLIST_INSERT_TAIL(&tone_zones, zone, list);
@@ -515,12 +515,12 @@ int ast_unregister_indication_country(const char *country)
                        current_tonezone = NULL;
                }
                /* Remove from the list */
-               AST_RWLIST_REMOVE_CURRENT(&tone_zones, list);
+               AST_RWLIST_REMOVE_CURRENT(list);
                ast_verb(3, "Unregistered indication country '%s'\n", tz->country);
                free_zone(tz);
                res = 0;
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&tone_zones);
 
        return res;
index d8567c8..e51505e 100644 (file)
@@ -169,7 +169,7 @@ void ast_module_unregister(const struct ast_module_info *info)
        AST_LIST_LOCK(&module_list);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) {
                if (mod->info == info) {
-                       AST_LIST_REMOVE_CURRENT(&module_list, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        break;
                }
        }
@@ -825,7 +825,7 @@ int load_modules(unsigned int preload_only)
 
                AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) {
                        if (!resource_name_match(order->resource, v->value)) {
-                               AST_LIST_REMOVE_CURRENT(&load_order, entry);
+                               AST_LIST_REMOVE_CURRENT(entry);
                                ast_free(order->resource);
                                ast_free(order);
                        }
@@ -849,7 +849,7 @@ int load_modules(unsigned int preload_only)
                switch (load_resource(order->resource, 1)) {
                case AST_MODULE_LOAD_SUCCESS:
                case AST_MODULE_LOAD_DECLINE:
-                       AST_LIST_REMOVE_CURRENT(&load_order, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        ast_free(order->resource);
                        ast_free(order);
                        break;
@@ -868,7 +868,7 @@ int load_modules(unsigned int preload_only)
                switch (load_resource(order->resource, 0)) {
                case AST_MODULE_LOAD_SUCCESS:
                case AST_MODULE_LOAD_DECLINE:
-                       AST_LIST_REMOVE_CURRENT(&load_order, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        ast_free(order->resource);
                        ast_free(order);
                        break;
@@ -961,7 +961,7 @@ int ast_loader_unregister(int (*v)(void))
        AST_LIST_LOCK(&module_list);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) {
                if (cur->updater == v)  {
-                       AST_LIST_REMOVE_CURRENT(&updaters, entry);
+                       AST_LIST_REMOVE_CURRENT(entry);
                        break;
                }
        }
index 4f16852..c1c8751 100644 (file)
@@ -1166,12 +1166,12 @@ int ast_unregister_verbose(void (*v)(const char *string))
        AST_RWLIST_WRLOCK(&verbosers);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&verbosers, cur, list) {
                if (cur->verboser == v) {
-                       AST_RWLIST_REMOVE_CURRENT(&verbosers, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        free(cur);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&verbosers);
        
        return cur ? 0 : -1;
index bc5ca1b..c329a94 100644 (file)
@@ -2598,7 +2598,7 @@ static void purge_sessions(int n_max)
        AST_LIST_LOCK(&sessions);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
                if (s->sessiontimeout && (now > s->sessiontimeout) && !s->inuse) {
-                       AST_LIST_REMOVE_CURRENT(&sessions, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        ast_atomic_fetchadd_int(&num_sessions, -1);
                        if (s->authenticated && (option_verbose > 1) && manager_displayconnects(s)) {
                                ast_verb(2, "HTTP Manager '%s' timed out from %s\n",
@@ -2609,7 +2609,7 @@ static void purge_sessions(int n_max)
                                break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&sessions);
 }
 
@@ -2719,13 +2719,13 @@ int ast_manager_unregister(char *action)
        AST_RWLIST_WRLOCK(&actions);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&actions, cur, list) {
                if (!strcasecmp(action, cur->action)) {
-                       AST_RWLIST_REMOVE_CURRENT(&actions, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(cur);
                        ast_verb(2, "Manager unregistered action %s\n", action);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&actions);
 
        return 0;
@@ -3476,7 +3476,7 @@ static int __init_manager(int reload)
                        continue;
                }
                /* We do not need to keep this user so take them out of the list */
-               AST_RWLIST_REMOVE_CURRENT(&users, list);
+               AST_RWLIST_REMOVE_CURRENT(list);
                /* Free their memory now */
                if (user->secret)
                        ast_free(user->secret);
@@ -3490,7 +3490,7 @@ static int __init_manager(int reload)
                        ast_free(user->write);
                ast_free(user);
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        AST_RWLIST_UNLOCK(&users);
 
index d740e91..d3949ec 100644 (file)
@@ -1514,12 +1514,12 @@ int ast_custom_function_unregister(struct ast_custom_function *acf)
        AST_RWLIST_WRLOCK(&acf_root);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
                if (cur == acf) {
-                       AST_RWLIST_REMOVE_CURRENT(&acf_root, acflist);
+                       AST_RWLIST_REMOVE_CURRENT(acflist);
                        ast_verb(2, "Unregistered custom function %s\n", acf->name);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&acf_root);
 
        return acf ? 0 : -1;
@@ -1547,11 +1547,11 @@ int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_m
        /* Store in alphabetical order */
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
                if (strcasecmp(acf->name, cur->name) < 0) {
-                       AST_RWLIST_INSERT_BEFORE_CURRENT(&acf_root, acf, acflist);
+                       AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        if (!cur)
                AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
 
@@ -2361,13 +2361,13 @@ static int ast_remove_hint(struct ast_exten *e)
                                ast_free(cbprev);
                        }
                        hint->callbacks = NULL;
-                       AST_RWLIST_REMOVE_CURRENT(&hints, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_free(hint);
                        res = 0;
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        return res;
 }
@@ -2935,13 +2935,13 @@ int ast_context_remove_switch2(struct ast_context *con, const char *sw, const ch
                if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
                        (!registrar || !strcmp(i->registrar, registrar))) {
                        /* found, remove from list */
-                       AST_LIST_REMOVE_CURRENT(&con->alts, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        ast_free(i); /* free switch and return */
                        ret = 0;
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
        ast_unlock_context(con);
 
@@ -3136,11 +3136,11 @@ int ast_register_application2(const char *app, int (*execute)(struct ast_channel
        /* Store in alphabetical order */
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
                if (strcasecmp(tmp->name, cur->name) < 0) {
-                       AST_RWLIST_INSERT_BEFORE_CURRENT(&apps, tmp, list);
+                       AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        if (!cur)
                AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
 
@@ -4023,13 +4023,13 @@ int ast_unregister_application(const char *app)
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
                if (!strcasecmp(app, tmp->name)) {
                        unreference_cached_app(tmp);
-                       AST_RWLIST_REMOVE_CURRENT(&apps, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_verb(2, "Unregistered application '%s'\n", tmp->name);
                        ast_free(tmp);
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&apps);
 
        return tmp ? 0 : -1;
index a68692d..986badd 100644 (file)
@@ -177,11 +177,11 @@ static void schedule(struct sched_context *con, struct sched *s)
        
        AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, cur, list) {
                if (ast_tvcmp(s->when, cur->when) == -1) {
-                       AST_LIST_INSERT_BEFORE_CURRENT(&con->schedq, s, list);
+                       AST_LIST_INSERT_BEFORE_CURRENT(s, list);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        if (!cur)
                AST_LIST_INSERT_TAIL(&con->schedq, s, list);
        
@@ -278,13 +278,13 @@ int ast_sched_del(struct sched_context *con, int id)
        ast_mutex_lock(&con->lock);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, s, list) {
                if (s->id == id) {
-                       AST_LIST_REMOVE_CURRENT(&con->schedq, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        con->schedcnt--;
                        sched_release(con, s);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 
 #ifdef DUMP_SCHEDULER
        /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */
index 898195d..e9c6d65 100644 (file)
@@ -132,7 +132,7 @@ static int srv_callback(void *context, unsigned char *answer, int len, unsigned
                if (current->priority <= entry->priority)
                        continue;
 
-               AST_LIST_INSERT_BEFORE_CURRENT(&c->entries, entry, list);
+               AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
                entry = NULL;
                break;
        }
@@ -167,8 +167,7 @@ static void process_weights(struct srv_context *context)
                        if (current->priority != cur_priority)
                                break;
 
-                       AST_LIST_REMOVE_CURRENT(&context->entries, list);
-                       AST_LIST_INSERT_TAIL(&temp_list, current, list);
+                       AST_LIST_MOVE_CURRENT(&temp_list, list);
                }
                AST_LIST_TRAVERSE_SAFE_END;
 
@@ -190,8 +189,7 @@ static void process_weights(struct srv_context *context)
                                if (current->weight < random_weight)
                                        continue;
 
-                               AST_LIST_REMOVE_CURRENT(&temp_list, list);
-                               AST_LIST_INSERT_TAIL(&newlist, current, list);
+                               AST_LIST_MOVE_CURRENT(&newlist, list);
                        }
                        AST_LIST_TRAVERSE_SAFE_END;
                }
index 09722a4..aa09643 100644 (file)
@@ -654,7 +654,7 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
                if ((u->srcfmt == t->srcfmt) &&
                    (u->dstfmt == t->dstfmt) &&
                    (u->cost > t->cost)) {
-                       AST_RWLIST_INSERT_BEFORE_CURRENT(&translators, t, list);
+                       AST_RWLIST_INSERT_BEFORE_CURRENT(t, list);
                        t = NULL;
                }
        }
@@ -682,7 +682,7 @@ int ast_unregister_translator(struct ast_translator *t)
        AST_RWLIST_WRLOCK(&translators);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
                if (u == t) {
-                       AST_RWLIST_REMOVE_CURRENT(&translators, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        ast_verb(2, "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt));
                        found = 1;
                        break;
index 7f3e066..2a03cb6 100644 (file)
@@ -3690,11 +3690,11 @@ static void reschedule_precache(const char *number, const char *context, int exp
        AST_LIST_LOCK(&pcq);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&pcq, qe, list) {
                if (!strcmp(number, qe->number) && !strcasecmp(context, qe->context)) {
-                       AST_LIST_REMOVE_CURRENT(&pcq, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        if (!qe) {
                len = sizeof(*qe);
                len += strlen(number) + 1;
@@ -4195,11 +4195,11 @@ static void prune_peers(void)
        AST_LIST_LOCK(&peers);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&peers, peer, list) {
                if (peer->dead) {
-                       AST_LIST_REMOVE_CURRENT(&peers, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        destroy_peer(peer);
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&peers);
 }
 
@@ -4210,11 +4210,11 @@ static void prune_mappings(void)
        AST_LIST_LOCK(&peers);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&mappings, map, list) {
                if (map->dead) {
-                       AST_LIST_REMOVE_CURRENT(&mappings, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        destroy_map(map);
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        AST_LIST_UNLOCK(&peers);
 }
 
index 293d54b..bb591c1 100644 (file)
@@ -1701,14 +1701,14 @@ int ast_agi_unregister(struct ast_module *mod, agi_command *cmd)
        AST_RWLIST_WRLOCK(&agi_commands);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
                if (cmd == e) {
-                       AST_RWLIST_REMOVE_CURRENT(&agi_commands, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        if (mod != ast_module_info->self)
                                ast_module_unref(ast_module_info->self);
                        unregistered=1;
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&agi_commands);
        if (unregistered)
                ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
index 17b7789..b32837b 100644 (file)
@@ -474,13 +474,13 @@ static void crypto_load(int ifd, int ofd)
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
                if (key->delme) {
                        ast_debug(1, "Deleting key %s type %d\n", key->name, key->ktype);
-                       AST_RWLIST_REMOVE_CURRENT(&keys, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        if (key->rsa)
                                RSA_free(key->rsa);
                        ast_free(key);
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
 
        AST_RWLIST_UNLOCK(&keys);
 }
index a779da0..e4fec53 100644 (file)
@@ -2129,7 +2129,7 @@ static void *do_parking_thread(void *ignore)
                                        ast_hangup(chan);
                                }
                                /* And take them out of the parking lot */
-                               AST_LIST_REMOVE_CURRENT(&parkinglot, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                con = ast_context_find(parking_con);
                                if (con) {
                                        if (ast_context_remove_extension2(con, pu->parkingexten, 1, NULL))
@@ -2163,7 +2163,7 @@ static void *do_parking_thread(void *ignore)
                                                ast_verb(2, "%s got tired of being parked\n", chan->name);
                                                ast_hangup(chan);
                                                /* And take them out of the parking lot */
-                                               AST_LIST_REMOVE_CURRENT(&parkinglot, list);
+                                               AST_LIST_REMOVE_CURRENT(list);
                                                con = ast_context_find(parking_con);
                                                if (con) {
                                                        if (ast_context_remove_extension2(con, pu->parkingexten, 1, NULL))
@@ -2270,7 +2270,7 @@ static int park_exec(struct ast_channel *chan, void *data)
        AST_LIST_LOCK(&parkinglot);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&parkinglot, pu, list) {
                if (pu->parkingnum == park) {
-                       AST_LIST_REMOVE_CURRENT(&parkinglot, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        break;
                }
        }
index c4d626c..464f6a2 100644 (file)
@@ -1493,14 +1493,14 @@ static void aji_handle_message(struct aji_client *client, ikspak *pak)
        AST_LIST_LOCK(&client->messages);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&client->messages, tmp, list) {
                if (flag) {
-                       AST_LIST_REMOVE_CURRENT(&client->messages, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        if (tmp->from)
                                ast_free(tmp->from);
                        if (tmp->message)
                                ast_free(tmp->message);
                } else if (difftime(time(NULL), tmp->arrived) >= client->message_timeout) {
                        flag = 1;
-                       AST_LIST_REMOVE_CURRENT(&client->messages, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        if (tmp->from)
                                ast_free(tmp->from);
                        if (tmp->message)
index 374864b..a1de8ba 100644 (file)
@@ -1293,14 +1293,14 @@ static int init_classes(int reload)
        AST_RWLIST_WRLOCK(&mohclasses);
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&mohclasses, moh, list) {
                if (reload && moh->delete) {
-                       AST_RWLIST_REMOVE_CURRENT(&mohclasses, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        if (!moh->inuse)
                                ast_moh_destroy_one(moh);
                } else if (moh->total_files) {
                        if (moh_scan_files(moh) <= 0) {
                                ast_log(LOG_WARNING, "No files found for class '%s'\n", moh->name);
                                moh->delete = 1;
-                               AST_LIST_REMOVE_CURRENT(&mohclasses, list);
+                               AST_LIST_REMOVE_CURRENT(list);
                                if (!moh->inuse)
                                        ast_moh_destroy_one(moh);
                        }
index 6475e33..0b38872 100644 (file)
@@ -706,15 +706,13 @@ static int reload(void)
        /* Purge classes that we know can go away (pooled with 0, only) */
        AST_LIST_TRAVERSE_SAFE_BEGIN(&odbc_list, class, list) {
                if (class->delme && class->haspool && class->count == 0) {
-                       AST_LIST_TRAVERSE_SAFE_BEGIN(&(class->odbc_obj), current, list) {
-                               AST_LIST_REMOVE_CURRENT(&(class->odbc_obj), list);
+                       while ((current = AST_LIST_REMOVE_HEAD(&class->odbc_obj, list))) {
                                odbc_obj_disconnect(current);
                                ast_mutex_destroy(&current->lock);
                                ast_free(current);
                        }
-                       AST_LIST_TRAVERSE_SAFE_END;
 
-                       AST_LIST_REMOVE_CURRENT(&odbc_list, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        ast_free(class);
                }
        }
index cb096d3..27b1d32 100644 (file)
@@ -317,7 +317,7 @@ int ast_speech_unregister(char *engine_name)
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&engines, engine, list) {
                if (!strcasecmp(engine->name, engine_name)) {
                        /* We have our engine... removed it */
-                       AST_RWLIST_REMOVE_CURRENT(&engines, list);
+                       AST_RWLIST_REMOVE_CURRENT(list);
                        /* If this was the default engine, we need to pick a new one */
                        if (!default_engine)
                                default_engine = AST_RWLIST_FIRST(&engines);
@@ -327,7 +327,7 @@ int ast_speech_unregister(char *engine_name)
                        break;
                }
        }
-       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&engines);
 
        return res;
index 117fc1c..1e48e83 100644 (file)
@@ -127,14 +127,15 @@ static struct ast_chan *find_chan(char *name)
 static void del_chan(char *name)
 {
        struct ast_chan *chan;
+
        AST_LIST_TRAVERSE_SAFE_BEGIN(&chans, chan, list) {
                if (!strcmp(name, chan->name)) {
-                       AST_LIST_REMOVE_CURRENT(&chans, list);
+                       AST_LIST_REMOVE_CURRENT(list);
                        free(chan);
                        return;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
 }
 
 static void fdprintf(int fd, char *fmt, ...)