[svn-commits] mmichelson: branch mmichelson/issue13220 r182959 - /team/mmichelson/issue1322...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 18 14:10:46 CDT 2009


Author: mmichelson
Date: Wed Mar 18 14:10:43 2009
New Revision: 182959

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182959
Log:
Remove locking from num_available_members so that callers can handle the locking themselves.


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

Modified: team/mmichelson/issue13220/apps/app_queue.c
URL: http://svn.digium.com/svn-view/asterisk/team/mmichelson/issue13220/apps/app_queue.c?view=diff&rev=182959&r1=182958&r2=182959
==============================================================================
--- team/mmichelson/issue13220/apps/app_queue.c (original)
+++ team/mmichelson/issue13220/apps/app_queue.c Wed Mar 18 14:10:43 2009
@@ -1717,15 +1717,14 @@
 	}
 }
 
+/* We assume that q is locked prior to this call */
 static int num_available_members(struct call_queue *q)
 {
 	struct member *mem;
 	int avl = 0;
 	struct ao2_iterator mem_iter;
 
-	ast_mutex_lock(&q->lock);
-
-	if (q->strategy == QUEUE_STRATEGY_RINGALL) {
+	if (!q->autofill || q->strategy == QUEUE_STRATEGY_RINGALL) {
 		ast_mutex_unlock(&q->lock);
 		return 1;
 	}
@@ -1746,7 +1745,6 @@
 		ao2_ref(mem, -1);
 	}
 
-	ast_mutex_unlock(&q->lock);
 	return avl;
 }
 
@@ -2383,54 +2381,38 @@
 {
 	struct queue_ent *ch;
 	int res;
-
-	if (!qe->parent->autofill) {
-		/* Atomically read the parent head -- does not need a lock */
-		ch = qe->parent->head;
-		/* If we are now at the top of the head, break out */
-		if (ch == qe) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "It's our turn (%s).\n", qe->chan->name);
-			res = 1;
-		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
-			res = 0;
-		}	
-
+	int avl;
+	int idx = 0;
+	/* This needs a lock. How many members are available to be served? */
+	ast_mutex_lock(&qe->parent->lock);
+
+	avl = num_available_members(qe->parent);
+		
+	ch = qe->parent->head;
+
+	if (option_debug) {
+		ast_log(LOG_DEBUG, "There are %d available members.\n", avl);
+	}
+
+	while ((idx < avl) && (ch) && (ch != qe)) {
+		if (!ch->pending)
+			idx++;
+		ch = ch->next;			
+	}
+
+	ast_mutex_unlock(&qe->parent->lock);
+
+	/* If the queue entry is within avl [the number of available members] calls from the top ... */
+	if (ch && idx < avl) {
+		if (option_debug)
+			ast_log(LOG_DEBUG, "It's our turn (%s).\n", qe->chan->name);
+		res = 1;
 	} else {
-		int avl = num_available_members(qe->parent);
-		int idx = 0;
-		/* This needs a lock. How many members are available to be served? */
-		ast_mutex_lock(&qe->parent->lock);
-			
-		ch = qe->parent->head;
-
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "There are %d available members.\n", avl);
-		}
+		if (option_debug)
+			ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
+		res = 0;
+	}
 	
-		while ((idx < avl) && (ch) && (ch != qe)) {
-			if (!ch->pending)
-				idx++;
-			ch = ch->next;			
-		}
-
-		ast_mutex_unlock(&qe->parent->lock);
-	
-		/* If the queue entry is within avl [the number of available members] calls from the top ... */
-		if (ch && idx < avl) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "It's our turn (%s).\n", qe->chan->name);
-			res = 1;
-		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "It's not our turn (%s).\n", qe->chan->name);
-			res = 0;
-		}
-		
-	}
-
 	return res;
 }
 /*! \brief The waiting areas for callers who are not actively calling members




More information about the svn-commits mailing list