[asterisk-commits] mmichelson: branch mmichelson/queue-reset r166959 - /team/mmichelson/queue-re...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Dec 31 14:03:46 CST 2008
Author: mmichelson
Date: Wed Dec 31 14:03:45 2008
New Revision: 166959
URL: http://svn.digium.com/view/asterisk?view=rev&rev=166959
Log:
A progress check-in
* Change operations on the use_weight global variable
to be atomic
* Use ast_trim_blanks instead of trying to do the same
operation in-place
* Change a bunch of one-line conditionals to use braces
Modified:
team/mmichelson/queue-reset/apps/app_queue.c
Modified: team/mmichelson/queue-reset/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/queue-reset/apps/app_queue.c?view=diff&rev=166959&r1=166958&r2=166959
==============================================================================
--- team/mmichelson/queue-reset/apps/app_queue.c (original)
+++ team/mmichelson/queue-reset/apps/app_queue.c Wed Dec 31 14:03:45 2008
@@ -1810,19 +1810,25 @@
return NULL;
}
}
- if (q)
+ if (q) {
prev_weight = q->weight ? 1 : 0;
+ }
q = find_queue_by_name_rt(queuename, queue_vars, member_config);
- if (member_config)
+ if (member_config) {
ast_config_destroy(member_config);
- if (queue_vars)
+ }
+ if (queue_vars) {
ast_variables_destroy(queue_vars);
+ }
/* update the use_weight value if the queue's has gained or lost a weight */
- if (!q->weight && prev_weight)
- use_weight--;
- if (q->weight && !prev_weight)
- use_weight++;
+ if (!q->weight && prev_weight) {
+ ast_atomic_fetchadd_int(&use_weight, -1);
+ }
+ if (q->weight && !prev_weight) {
+ ast_atomic_fetchadd_int(&use_weight, +1);
+ }
+ /* Other cases will end up with the proper value for use_weight */
ao2_unlock(queues);
} else {
@@ -5510,7 +5516,6 @@
AST_APP_ARG(state_interface);
);
-
/* Add a new member */
parse = ast_strdupa(memberdata);
@@ -5519,25 +5524,28 @@
interface = args.interface;
if (!ast_strlen_zero(args.penalty)) {
tmp = args.penalty;
- while (*tmp && *tmp < 33) tmp++;
+ ast_trim_blanks(tmp);
penalty = atoi(tmp);
if (penalty < 0) {
penalty = 0;
}
- } else
+ } else {
penalty = 0;
+ }
if (!ast_strlen_zero(args.membername)) {
membername = args.membername;
- while (*membername && *membername < 33) membername++;
- } else
+ ast_trim_blanks(membername);
+ } else {
membername = interface;
+ }
if (!ast_strlen_zero(args.state_interface)) {
state_interface = args.state_interface;
- while (*state_interface && *state_interface < 33) state_interface++;
- } else
+ ast_trim_blanks(state_interface);
+ } else {
state_interface = interface;
+ }
/* Find the old position in the list */
ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
@@ -5547,8 +5555,9 @@
ao2_ref(newm, -1);
newm = NULL;
- if (cur)
+ if (cur) {
ao2_ref(cur, -1);
+ }
else {
q->membercount++;
}
@@ -5575,20 +5584,18 @@
if (queue_reload) {
/* Make one then */
if (!(q = alloc_queue(queuename))) {
- /* TODO: Handle memory allocation failure */
- /* XXX Putting a dummy return here for now so that I can remove the
- * unneeded if(q) down below
- */
return;
}
- } else
+ } else {
/* Since we're not reloading queues, this means that we found a queue
* in the configuration file which we don't know about yet. Just return.
*/
return;
+ }
new = 1;
- } else
+ } else {
new = 0;
+ }
if (!new) {
ao2_lock(q);
@@ -5614,8 +5621,9 @@
tmpvar, q->name);
q->strategy = QUEUE_STRATEGY_RINGALL;
}
- } else
+ } else {
q->strategy = QUEUE_STRATEGY_RINGALL;
+ }
/* Re-initialize the queue */
init_queue(q);
}
@@ -5623,33 +5631,37 @@
q->membercount = 0;
mem_iter = ao2_iterator_init(q->members, 0);
while ((cur = ao2_iterator_next(&mem_iter))) {
- if (!cur->dynamic)
+ if (!cur->dynamic) {
cur->delme = 1;
+ }
ao2_ref(cur, -1);
}
}
for (var = ast_variable_browse(cfg, queuename); var; var = var->next) {
- if (!strcasecmp(var->name, "member")) {
- if (member_reload)
- reload_single_member(var->value, q);
- } else if (queue_reload)
+ if (member_reload && !strcasecmp(var->name, "member")) {
+ reload_single_member(var->value, q);
+ } else if (queue_reload) {
queue_set_param(q, var->name, var->value, var->lineno, 1);
+ }
}
/* At this point, we've determined if the queue has a weight, so update use_weight
* as appropriate
*/
- if (!q->weight && prev_weight)
- use_weight--;
- else if (q->weight && !prev_weight)
- use_weight++;
+ if (!q->weight && prev_weight) {
+ ast_atomic_fetchadd_int(&use_weight, -1);
+ }
+ else if (q->weight && !prev_weight) {
+ ast_atomic_fetchadd_int(&use_weight, +1);
+ }
/* Free remaining members marked as delme */
if (member_reload) {
mem_iter = ao2_iterator_init(q->members, 0);
while ((cur = ao2_iterator_next(&mem_iter))) {
if (!cur->delme) {
- if (cur->dynamic)
+ if (cur->dynamic) {
q->membercount++;
+ }
cur->status = ast_device_state(cur->interface);
ao2_ref(cur, -1);
continue;
@@ -5662,8 +5674,9 @@
if (new) {
ao2_link(queues, q);
- } else
+ } else {
ao2_unlock(q);
+ }
queue_unref(q);
}
More information about the asterisk-commits
mailing list