aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_queue.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-06 01:33:01 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-06 01:33:01 +0000
commit28ac723a337536809c6d8f363ff84037a548f690 (patch)
treeb32c9541ad363f4d005d8e98b92952fc366c9b08 /apps/app_queue.c
parenta95870bdebdce6b672ff5bce92d9d3914c7858b0 (diff)
Merged revisions 222176 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r222176 | kpfleming | 2009-10-05 20:24:24 -0500 (Mon, 05 Oct 2009) | 27 lines Recorded merge of revisions 222152 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r222152 | kpfleming | 2009-10-05 20:16:36 -0500 (Mon, 05 Oct 2009) | 20 lines Fix ao2_iterator API to hold references to containers being iterated. See Mantis issue for details of what prompted this change. Additional notes: This patch changes the ao2_iterator API in two ways: F_AO2I_DONTLOCK has become an enum instead of a macro, with a name that fits our naming policy; also, it is now necessary to call ao2_iterator_destroy() on any iterator that has been created. Currently this only releases the reference to the container being iterated, but in the future this could also release other resources used by the iterator, if the iterator implementation changes to use additional resources. (closes issue #15987) Reported by: kpfleming Review: https://reviewboard.asterisk.org/r/383/ ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@222185 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_queue.c')
-rw-r--r--apps/app_queue.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index aca8aaf24..351e6b331 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -670,11 +670,13 @@ static enum queue_member_status get_member_status(struct call_queue *q, int max_
} else {
ao2_unlock(q);
ao2_ref(member, -1);
+ ao2_iterator_destroy(&mem_iter);
return QUEUE_NORMAL;
}
break;
}
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
return result;
@@ -756,7 +758,6 @@ static void *handle_statechange(struct statechange *sc)
if ((slash_pos = strchr(interface, '/')))
if ((slash_pos = strchr(slash_pos + 1, '/')))
*slash_pos = '\0';
-
if (!strcasecmp(interface, sc->dev))
break;
}
@@ -1025,7 +1026,7 @@ static int interface_exists_global(const char *interface, int lock_queue_contain
int ret = 0;
ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
- queue_iter = ao2_iterator_init(queues, lock_queue_container ? 0 : F_AO2I_DONTLOCK);
+ queue_iter = ao2_iterator_init(queues, lock_queue_container ? 0 : AO2_ITERATOR_DONTLOCK);
while ((q = ao2_iterator_next(&queue_iter))) {
ao2_lock(q);
mem_iter = ao2_iterator_init(q->members, 0);
@@ -1038,7 +1039,9 @@ static int interface_exists_global(const char *interface, int lock_queue_contain
}
ao2_unlock(q);
queue_unref(q);
+ ao2_iterator_destroy(&mem_iter);
}
+ ao2_iterator_destroy(&queue_iter);
return ret;
}
@@ -1415,6 +1418,7 @@ static void free_members(struct call_queue *q, int all)
}
ao2_ref(cur, -1);
}
+ ao2_iterator_destroy(&mem_iter);
}
/*! \brief Free queue's member list then its string fields */
@@ -1562,6 +1566,7 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
m->dead = 1;
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
while ((interface = ast_category_browse(member_config, interface))) {
rt_handle_member_record(q, interface,
@@ -1581,6 +1586,7 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
@@ -1680,6 +1686,7 @@ static void update_realtime_members(struct call_queue *q)
m->dead = 1;
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
while ((interface = ast_category_browse(member_config, interface))) {
rt_handle_member_record(q, interface,
@@ -1699,6 +1706,7 @@ static void update_realtime_members(struct call_queue *q)
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
ao2_unlock(queues);
ast_config_destroy(member_config);
@@ -2095,6 +2103,7 @@ static int num_available_members(struct call_queue *q)
break;
}
}
+ ao2_iterator_destroy(&mem_iter);
return avl;
}
@@ -2133,6 +2142,7 @@ static int compare_weight(struct call_queue *rq, struct member *member)
break;
}
}
+ ao2_iterator_destroy(&queue_iter);
return found;
}
@@ -3021,6 +3031,7 @@ static int update_queue(struct call_queue *q, struct member *member, int callcom
ao2_unlock(qtmp);
ao2_ref(qtmp, -1);
}
+ ao2_iterator_destroy(&queue_iter);
} else {
ao2_lock(q);
time(&member->lastcall);
@@ -3425,6 +3436,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
if (!tmp) {
ao2_ref(cur, -1);
ao2_unlock(qe->parent);
+ ao2_iterator_destroy(&memi);
if (use_weight)
ao2_unlock(queues);
goto out;
@@ -3433,6 +3445,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
if (!(datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL))) {
ao2_ref(cur, -1);
ao2_unlock(qe->parent);
+ ao2_iterator_destroy(&memi);
if (use_weight)
ao2_unlock(queues);
free(tmp);
@@ -3442,6 +3455,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
ao2_ref(cur, -1);
ao2_unlock(&qe->parent);
+ ao2_iterator_destroy(&memi);
if (use_weight)
ao2_unlock(queues);
free(tmp);
@@ -3479,6 +3493,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
if (!(di = ast_calloc(1, sizeof(*di) + strlen(cur->interface)))) {
ao2_ref(cur, -1);
ao2_unlock(qe->parent);
+ ao2_iterator_destroy(&memi);
if (use_weight)
ao2_unlock(queues);
free(tmp);
@@ -4036,10 +4051,13 @@ static struct member *interface_exists(struct call_queue *q, const char *interfa
mem_iter = ao2_iterator_init(q->members, 0);
while ((mem = ao2_iterator_next(&mem_iter))) {
- if (!strcasecmp(interface, mem->interface))
+ if (!strcasecmp(interface, mem->interface)) {
+ ao2_iterator_destroy(&mem_iter);
return mem;
+ }
ao2_ref(mem, -1);
}
+ ao2_iterator_destroy(&mem_iter);
return NULL;
}
@@ -4080,6 +4098,7 @@ static void dump_queue_members(struct call_queue *pm_queue)
}
value_len += res;
}
+ ao2_iterator_destroy(&mem_iter);
if (value_len && !cur_member) {
if (ast_db_put(pm_family, pm_queue->name, value))
@@ -4267,6 +4286,7 @@ static int set_member_paused(const char *queuename, const char *interface, const
ao2_unlock(q);
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
return found ? RESULT_SUCCESS : RESULT_FAILURE;
}
@@ -4305,6 +4325,7 @@ static int set_member_penalty(char *queuename, char *interface, int penalty)
ao2_unlock(q);
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
if (foundinterface) {
return RESULT_SUCCESS;
@@ -5097,6 +5118,7 @@ static int queue_function_qac(struct ast_channel *chan, const char *cmd, char *d
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
} else if (!strcasecmp(option, "free")) {
mem_iter = ao2_iterator_init(q->members, 0);
while ((m = ao2_iterator_next(&mem_iter))) {
@@ -5106,6 +5128,7 @@ static int queue_function_qac(struct ast_channel *chan, const char *cmd, char *d
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
} else /* must be "count" */
count = q->membercount;
ao2_unlock(q);
@@ -5151,6 +5174,7 @@ static int queue_function_qac_dep(struct ast_channel *chan, const char *cmd, cha
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
queue_unref(q);
} else
@@ -5234,6 +5258,7 @@ static int queue_function_queuememberlist(struct ast_channel *chan, const char *
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
queue_unref(q);
} else
@@ -5463,7 +5488,7 @@ static int reload_queues(int reload)
ao2_lock(queues);
use_weight=0;
/* Mark all queues as dead for the moment */
- queue_iter = ao2_iterator_init(queues, F_AO2I_DONTLOCK);
+ queue_iter = ao2_iterator_init(queues, AO2_ITERATOR_DONTLOCK);
while ((q = ao2_iterator_next(&queue_iter))) {
if (!q->realtime) {
q->dead = 1;
@@ -5700,7 +5725,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
}
}
- queue_iter = ao2_iterator_init(queues, F_AO2I_DONTLOCK);
+ queue_iter = ao2_iterator_init(queues, AO2_ITERATOR_DONTLOCK);
ao2_lock(queues);
while ((q = ao2_iterator_next(&queue_iter))) {
float sl;
@@ -5764,6 +5789,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
do_print(s, fd, out->str);
ao2_ref(mem, -1);
}
+ ao2_iterator_destroy(&mem_iter);
}
if (!q->head)
do_print(s, fd, " No Callers");
@@ -5783,6 +5809,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
ao2_unlock(q);
queue_unref(q); /* Unref the iterator's reference */
}
+ ao2_iterator_destroy(&queue_iter);
ao2_unlock(queues);
if (!found) {
if (argc == 3)
@@ -5811,6 +5838,7 @@ static char *complete_queue(const char *line, const char *word, int pos, int sta
}
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
return ret;
}
@@ -5919,6 +5947,7 @@ static int manager_queues_summary(struct mansession *s, const struct message *m)
}
ao2_ref(mem, -1);
}
+ ao2_iterator_destroy(&mem_iter);
for (qe = q->head; qe; qe = qe->next) {
if ((now - qe->start) > qlongestholdtime) {
qlongestholdtime = now - qe->start;
@@ -5939,6 +5968,7 @@ static int manager_queues_summary(struct mansession *s, const struct message *m)
ao2_unlock(q);
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
astman_append(s,
"Event: QueueSummaryComplete\r\n"
"%s"
@@ -6011,6 +6041,7 @@ static int manager_queues_status(struct mansession *s, const struct message *m)
}
ao2_ref(mem, -1);
}
+ ao2_iterator_destroy(&mem_iter);
/* List Queue Entries */
pos = 1;
for (qe = q->head; qe; qe = qe->next) {
@@ -6032,6 +6063,7 @@ static int manager_queues_status(struct mansession *s, const struct message *m)
ao2_unlock(q);
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
astman_append(s,
"Event: QueueStatusComplete\r\n"
@@ -6330,13 +6362,17 @@ static char *complete_queue_remove_member(const char *line, const char *word, in
tmp = ast_strdup(m->interface);
ao2_ref(m, -1);
queue_unref(q);
+ ao2_iterator_destroy(&mem_iter);
+ ao2_iterator_destroy(&queue_iter);
return tmp;
}
ao2_ref(m, -1);
}
+ ao2_iterator_destroy(&mem_iter);
ao2_unlock(q);
queue_unref(q);
}
+ ao2_iterator_destroy(&queue_iter);
return NULL;
}
@@ -6661,6 +6697,7 @@ static int unload_module(void)
ao2_unlink(queues, q);
queue_unref(q);
}
+ ao2_iterator_destroy(&q_iter);
ao2_ref(queues, -1);
return res;