[asterisk-commits] mmichelson: branch mmichelson/queue_refcount_trunk r82364 - /team/mmichelson/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 13 18:53:20 CDT 2007


Author: mmichelson
Date: Thu Sep 13 18:53:19 2007
New Revision: 82364

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82364
Log:
Changed all instances of locking from using ast_mutex_[un]lock to ao2_[un]lock


Modified:
    team/mmichelson/queue_refcount_trunk/apps/app_queue.c

Modified: team/mmichelson/queue_refcount_trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/queue_refcount_trunk/apps/app_queue.c?view=diff&rev=82364&r1=82363&r2=82364
==============================================================================
--- team/mmichelson/queue_refcount_trunk/apps/app_queue.c (original)
+++ team/mmichelson/queue_refcount_trunk/apps/app_queue.c Thu Sep 13 18:53:19 2007
@@ -348,7 +348,6 @@
 #define QUEUE_EVENT_VARIABLES 3
 
 struct call_queue {
-	ast_mutex_t lock;	
 	char name[80];                      /*!< Name */
 	char moh[80];                       /*!< Music On Hold class to be used */
 	char announce[80];                  /*!< Announcement to play when call is answered */
@@ -537,7 +536,7 @@
 	struct ao2_iterator mem_iter;
 	enum queue_member_status result = QUEUE_NO_MEMBERS;
 
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 	mem_iter = ao2_iterator_init(q->members, 0);
 	while ((member = ao2_iterator_next(&mem_iter))) {
 		if (max_penalty && (member->penalty > max_penalty)) {
@@ -559,7 +558,7 @@
 			if (member->paused) {
 				result = QUEUE_NO_UNPAUSED_REACHABLE_MEMBERS;
 			} else {
-				ast_mutex_unlock(&q->lock);
+				ao2_unlock(q);
 				ao2_ref(member, -1);
 				return QUEUE_NORMAL;
 			}
@@ -568,7 +567,7 @@
 	}
 
 	ao2_ref(member, -1);
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 	return result;
 }
 
@@ -618,7 +617,7 @@
 	ast_debug(1, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
 	queue_iter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_iterator_next(&queue_iter))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		mem_iter = ao2_iterator_init(q->members, 0);
 		while ((cur = ao2_iterator_next(&mem_iter))) {
 			char *interface;
@@ -656,7 +655,7 @@
 			ao2_ref(cur, -1);
 		}
 		queue_unref(q);
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 	}
 
 	return NULL;
@@ -877,14 +876,14 @@
 	queue_iter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_iterator_next(&queue_iter))) {
 
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if ((mem = ao2_find(q->members, &tmpmem, OBJ_POINTER))) {
 			ao2_ref(mem, -1);
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 			queue_unref(q);
 			break;
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 
@@ -1156,7 +1155,6 @@
 	struct call_queue *q = obj;
 	ast_debug(0, "Queue destructor called for queue '%s'!\n", q->name);
 	free_members(q, 1);
-	ast_mutex_destroy(&q->lock);
 	ao2_ref(q->members, -1);
 }
 
@@ -1165,7 +1163,6 @@
 	struct call_queue *q;
 
 	if ((q = ao2_alloc(sizeof(*q), destroy_queue))) {
-		ast_mutex_init(&q->lock);
 		ast_copy_string(q->name, queuename, sizeof(q->name));
 	}
 	return q;
@@ -1189,14 +1186,14 @@
 
 	/* Static queues override realtime. */
 	if ((q = ao2_find(queues, &tmpq, OBJ_POINTER))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if (!q->realtime) {
 			if (q->dead) {
-				ast_mutex_unlock(&q->lock);
+				ao2_unlock(q);
 				queue_unref(q);
 				return NULL;
 			} else {
-				ast_mutex_unlock(&q->lock);
+				ao2_unlock(q);
 				return q;
 			}
 		}
@@ -1217,7 +1214,7 @@
 			q->dead = 1;
 			/* Delete if unused (else will be deleted when last caller leaves). */
 			ao2_unlink(queues, q);
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 			queue_unref(q);
 		}
 		return NULL;
@@ -1227,7 +1224,7 @@
 	if (!q) {
 		if (!(q = alloc_queue(queuename)))
 			return NULL;
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		clear_queue(q);
 		q->realtime = 1;
 		init_queue(q);		/* Ensure defaults for all parameters not set explicitly. */
@@ -1271,15 +1268,15 @@
 	while ((m = ao2_iterator_next(&mem_iter))) {
 		if (m->dead) {
 			ao2_unlink(q->members, m);
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 			remove_from_interfaces(m->interface);
-			ast_mutex_lock(&q->lock);
+			ao2_lock(q);
 			q->membercount--;
 		}
 		ao2_ref(m, -1);
 	}
 
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 
 	return q;
 }
@@ -1360,7 +1357,7 @@
 		return;
 	}
 
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 	
 	/* Temporarily set realtime  members dead so we can detect deleted ones.*/ 
 	mem_iter = ao2_iterator_init(q->members, 0);
@@ -1382,14 +1379,14 @@
 	while ((m = ao2_iterator_next(&mem_iter))) {
 		if (m->dead) {
 			ao2_unlink(q->members, m);
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 			remove_from_interfaces(m->interface);
-			ast_mutex_lock(&q->lock);
+			ao2_lock(q);
 			q->membercount--;
 		}
 		ao2_ref(m, -1);
 	}
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 }
 
 static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
@@ -1405,7 +1402,7 @@
 		return res;
 
 	ao2_lock(queues);
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 
 	/* This is our one */
 	stat = get_member_status(q, qe->max_penalty);
@@ -1452,7 +1449,7 @@
 			q->name, qe->pos, q->count, qe->chan->uniqueid );
 		ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
 	}
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 	ao2_unlock(queues);
 
 	return res;
@@ -1626,10 +1623,10 @@
 	/* Thanks to SRT for this contribution */
 	/* 2^2 (4) is the filter coefficient; a higher exponent would give old entries more weight */
 
-	ast_mutex_lock(&qe->parent->lock);
+	ao2_lock(qe->parent);
 	oldvalue = qe->parent->holdtime;
 	qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newholdtime) >> 2;
-	ast_mutex_unlock(&qe->parent->lock);
+	ao2_unlock(qe->parent);
 }
 
 
@@ -1642,7 +1639,7 @@
 	if (!(q = qe->parent))
 		return;
 	queue_ref(q);
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 
 	prev = NULL;
 	for (cur = q->head; cur; cur = cur->next) {
@@ -1665,7 +1662,7 @@
 			prev = cur;
 		}
 	}
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 
 	/*If the queue is a realtime queue, check to see if it's still defined in real time*/
 	if(q->realtime) {
@@ -1705,7 +1702,7 @@
 
 	/* Since a reload could have taken place, we have to traverse the list to
 		be sure it's still valid */
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 	mem_iter = ao2_iterator_init(q->members, 0);
 	while ((cur = ao2_iterator_next(&mem_iter))) {
 		if (member != cur) {
@@ -1730,7 +1727,7 @@
 		}
 		ao2_ref(cur, -1);
 	}
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 	return 0;
 }
 
@@ -1764,7 +1761,7 @@
 			queue_unref(q);
 			continue;
 		}
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if (q->count && q->members) {
 			if ((mem = ao2_find(q->members, member, OBJ_POINTER))) {
 				ast_debug(1, "Found matching member %s in queue '%s'\n", mem->interface, q->name);
@@ -1775,7 +1772,7 @@
 				ao2_ref(mem, -1);
 			}
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		if (found) {
 			queue_unref(q);
 			break;
@@ -1885,9 +1882,9 @@
 		tmp->stillgoing = 0;
 		update_dial_status(qe->parent, tmp->member, status);
 
-		ast_mutex_lock(&qe->parent->lock);
+		ao2_lock(qe->parent);
 		qe->parent->rrpos++;
-		ast_mutex_unlock(&qe->parent->lock);
+		ao2_unlock(qe->parent);
 
 		(*busies)++;
 		return 0;
@@ -2066,7 +2063,7 @@
 
 static void record_abandoned(struct queue_ent *qe)
 {
-	ast_mutex_lock(&qe->parent->lock);
+	ao2_lock(qe->parent);
 	set_queue_variables(qe);
 	manager_event(EVENT_FLAG_AGENT, "QueueCallerAbandon",
 		"Queue: %s\r\n"
@@ -2077,7 +2074,7 @@
 		qe->parent->name, qe->chan->uniqueid, qe->pos, qe->opos, (int)(time(NULL) - qe->start));
 
 	qe->parent->callsabandoned++;
-	ast_mutex_unlock(&qe->parent->lock);
+	ao2_unlock(qe->parent);
 }
 
 /*! \brief RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer. */
@@ -2363,7 +2360,7 @@
 
 	} else {
 		/* This needs a lock. How many members are available to be served? */
-		ast_mutex_lock(&qe->parent->lock);
+		ao2_lock(qe->parent);
 			
 		ch = qe->parent->head;
 	
@@ -2400,7 +2397,7 @@
 			res = 0;
 		}
 		
-		ast_mutex_unlock(&qe->parent->lock);
+		ao2_unlock(qe->parent);
 	}
 
 	return res;
@@ -2471,13 +2468,13 @@
 
 static int update_queue(struct call_queue *q, struct member *member, int callcompletedinsl)
 {
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 	time(&member->lastcall);
 	member->calls++;
 	q->callscompleted++;
 	if (callcompletedinsl)
 		q->callscompletedinsl++;
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 	return 0;
 }
 
@@ -2647,7 +2644,7 @@
 	/* Hold the lock while we setup the outgoing calls */
 	if (use_weight)
 		ao2_lock(queues);
-	ast_mutex_lock(&qe->parent->lock);
+	ao2_lock(qe->parent);
 	ast_debug(1, "%s is trying to call a queue member.\n",
 							qe->chan->name);
 	ast_copy_string(queuename, qe->parent->name, sizeof(queuename));
@@ -2662,7 +2659,7 @@
 
 		if (!tmp) {
 			ao2_ref(cur, -1);
-			ast_mutex_unlock(&qe->parent->lock);
+			ao2_unlock(qe->parent);
 			if (use_weight)
 				ao2_unlock(queues);
 			goto out;
@@ -2694,15 +2691,15 @@
 		to = (qe->parent->timeout) ? qe->parent->timeout * 1000 : -1;
 	orig = to;
 	ring_one(qe, outgoing, &numbusies);
-	ast_mutex_unlock(&qe->parent->lock);
+	ao2_unlock(qe->parent);
 	if (use_weight)
 		ao2_unlock(queues);
 	lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed);
-	ast_mutex_lock(&qe->parent->lock);
+	ao2_lock(qe->parent);
 	if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
 		store_next(qe, outgoing);
 	}
-	ast_mutex_unlock(&qe->parent->lock);
+	ao2_unlock(qe->parent);
 	peer = lpeer ? lpeer->chan : NULL;
 	if (!peer) {
 		if (to) {
@@ -2726,9 +2723,9 @@
 		/* Update parameters for the queue */
 		time(&now);
 		recalc_holdtime(qe, (now - qe->start));
-		ast_mutex_lock(&qe->parent->lock);
+		ao2_lock(qe->parent);
 		callcompletedinsl = ((now - qe->start) <= qe->parent->servicelevel);
-		ast_mutex_unlock(&qe->parent->lock);
+		ao2_unlock(qe->parent);
 		member = lpeer->member;
 		hangupcalls(outgoing, peer);
 		outgoing = NULL;
@@ -2810,7 +2807,7 @@
 				ast_log(LOG_WARNING, "Announcement file '%s' is unavailable, continuing anyway...\n", qe->parent->sound_callerannounce);
 		}
 
-		ast_mutex_lock(&qe->parent->lock);
+		ao2_lock(qe->parent);
 		/* if setinterfacevar is defined, make member variables available to the channel */
 		/* use  pbx_builtin_setvar to set a load of variables with one call */
 		if (qe->parent->setinterfacevar) {
@@ -2829,7 +2826,7 @@
 	
 		/* try to set queue variables if configured to do so*/
 		set_queue_variables(qe);
-		ast_mutex_unlock(&qe->parent->lock);
+		ao2_unlock(qe->parent);
 		
 		/* Begin Monitoring */
 		if (qe->parent->monfmt && *qe->parent->monfmt) {
@@ -3160,7 +3157,7 @@
 	ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
 	ast_copy_string(tmpq.name, queuename, sizeof(tmpq.name));
 	if((q = ao2_find(queues, &tmpq, OBJ_POINTER))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if ((mem = ao2_find(q->members, &tmpmem, OBJ_POINTER | OBJ_UNLINK))) {
 			q->membercount--;
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved",
@@ -3177,7 +3174,7 @@
 		} else {
 			res = RES_EXISTS;
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 
@@ -3201,7 +3198,7 @@
 
 	ao2_lock(queues);
 
-	ast_mutex_lock(&q->lock);
+	ao2_lock(q);
 	if ((old_member = interface_exists(q, interface)) == NULL) {
 		add_to_interfaces(interface);
 		if ((new_member = create_queue_member(interface, membername, penalty, paused))) {
@@ -3234,7 +3231,7 @@
 		ao2_ref(old_member, -1);
 		res = RES_EXISTS;
 	}
-	ast_mutex_unlock(&q->lock);
+	ao2_unlock(q);
 	ao2_unlock(queues);
 
 	return res;
@@ -3254,7 +3251,7 @@
 
 	queue_iter = ao2_iterator_init(queues, 0);
 	while((q = ao2_iterator_next(&queue_iter))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
 			if ((mem = interface_exists(q, interface))) {
 				found++;
@@ -3290,7 +3287,7 @@
 				ao2_ref(mem, -1);
 			}
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 
@@ -3875,7 +3872,7 @@
 	ast_copy_string(tmpq.name, data, sizeof(tmpq.name));
 
 	if ((q = ao2_find(queues, &tmpq, OBJ_POINTER))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
         	if (q->setqueuevar) {
 		        sl = 0;
 			res = 0;
@@ -3890,7 +3887,7 @@
 		        pbx_builtin_setvar(chan, interfacevar);
 	        }
 
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	} else
 		ast_log(LOG_WARNING, "queue %s was not found\n", data);
@@ -3917,7 +3914,7 @@
 	ast_copy_string(tmpq.name, data, sizeof(tmpq.name));
 	
 	if ((q = ao2_find(queues, &tmpq, OBJ_POINTER))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		mem_iter = ao2_iterator_init(q->members, 0);
 		while ((m = ao2_iterator_next(&mem_iter))) {
 			/* Count the agents who are logged in and presently answering calls */
@@ -3926,7 +3923,7 @@
 			}
 			ao2_ref(m, -1);
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	} else
 		ast_log(LOG_WARNING, "queue %s was not found\n", data);
@@ -3951,9 +3948,9 @@
 	ast_copy_string(tmpq.name, data, sizeof(tmpq.name));
 	
 	if ((q = ao2_find(queues, &tmpq, OBJ_POINTER))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		count = q->count;
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	} else
 		ast_log(LOG_WARNING, "queue %s was not found\n", data);
@@ -3982,7 +3979,7 @@
 		int buflen = 0, count = 0;
 		struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0);
 
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		while ((m = ao2_iterator_next(&mem_iter))) {
 			/* strcat() is always faster than printf() */
 			if (count++) {
@@ -3999,7 +3996,7 @@
 			}
 			ao2_ref(m, -1);
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	} else
 		ast_log(LOG_WARNING, "queue %s was not found\n", data);
@@ -4123,7 +4120,7 @@
 				new = 0;
 			if (q) {
 				if (!new)
-					ast_mutex_lock(&q->lock);
+					ao2_lock(q);
 				/* Re-initialize the queue, and clear statistics */
 				init_queue(q);
 				if (!queue_keep_stats) 
@@ -4198,7 +4195,7 @@
 					ao2_link(queues, q);
 					queue_ref(q);
 				} else
-					ast_mutex_unlock(&q->lock);
+					ao2_unlock(q);
 				queue_unref(q);
 			}
 		}
@@ -4209,7 +4206,7 @@
 		if (q->dead) {
 			ao2_unlink(queues, q);
 		} else {
-			ast_mutex_lock(&q->lock);
+			ao2_lock(q);
 			mem_iter = ao2_iterator_init(q->members, 0);
 			while ((cur = ao2_iterator_next(&mem_iter))) {
 				if (cur->dynamic)
@@ -4217,7 +4214,7 @@
 				cur->status = ast_device_state(cur->interface);
 				ao2_ref(cur, -1);
 			}
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 		}
 		queue_unref(q);
 	}
@@ -4254,9 +4251,9 @@
 	while ((q = ao2_iterator_next(&queue_iter))) {
 		float sl;
 
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		if (argc == 3 && strcasecmp(q->name, argv[2])) {
-			ast_mutex_unlock(&q->lock);
+			ao2_unlock(q);
 			continue;
 		}
 		found = 1;
@@ -4313,7 +4310,7 @@
 			}
 		}
 		do_print(s, fd, "");	/* blank line between entries */
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		if (argc == 3)	{ /* print a specific entry */
 			queue_unref(q);
 			break;
@@ -4398,7 +4395,7 @@
 		snprintf(idText, 256, "ActionID: %s\r\n", id);
 	queue_iter = ao2_iterator_init(queues, 0);
 	while((q = ao2_iterator_next(&queue_iter))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 
 		/* List queue properties */
 		if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) {
@@ -4426,7 +4423,7 @@
 				"\r\n",
 				q->name, qmemcount, qmemavail, qchancount, q->holdtime, idText);
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 	astman_append(s,
@@ -4460,7 +4457,7 @@
 
 	queue_iter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_iterator_next(&queue_iter))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 
 		/* List queue properties */
 		if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) {
@@ -4518,7 +4515,7 @@
 					(long) (now - qe->start), idText);
 			}
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 
@@ -4798,12 +4795,12 @@
 	/* here is the case for 3, <member> */
 	queue_iter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_iterator_next(&queue_iter))) {
-		ast_mutex_lock(&q->lock);
+		ao2_lock(q);
 		mem_iter = ao2_iterator_init(q->members, 0);
 		while ((m = ao2_iterator_next(&mem_iter))) {
 			if (++which > state) {
 				char *tmp;
-				ast_mutex_unlock(&q->lock);
+				ao2_unlock(q);
 				tmp = ast_strdup(m->interface);
 				ao2_ref(m, -1);
 				queue_unref(q);
@@ -4811,7 +4808,7 @@
 			}
 			ao2_ref(m, -1);
 		}
-		ast_mutex_unlock(&q->lock);
+		ao2_unlock(q);
 		queue_unref(q);
 	}
 




More information about the asterisk-commits mailing list