[asterisk-commits] russell: branch russell/chan_refcount r100531 - /team/russell/chan_refcount/m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jan 27 22:24:38 CST 2008


Author: russell
Date: Sun Jan 27 22:24:38 2008
New Revision: 100531

URL: http://svn.digium.com/view/asterisk?view=rev&rev=100531
Log:
Convert the list of channel technology types to a RWLIST

Modified:
    team/russell/chan_refcount/main/channel.c

Modified: team/russell/chan_refcount/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/channel.c?view=diff&rev=100531&r1=100530&r2=100531
==============================================================================
--- team/russell/chan_refcount/main/channel.c (original)
+++ team/russell/chan_refcount/main/channel.c Sun Jan 27 22:24:38 2008
@@ -106,7 +106,7 @@
 };
 
 /*! \brief the list of registered channel types */
-static AST_LIST_HEAD_STATIC(backends, chanlist);
+static AST_RWLIST_HEAD_STATIC(backends, chanlist);
 
 #ifdef LOW_MEMORY
 #define MAX_CHANNEL_BUCKETS 61
@@ -177,8 +177,8 @@
 	struct chanlist *cl;
 	struct ast_variable *var=NULL, *prev = NULL;
 
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, cl, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, cl, list) {
 		if (prev)  {
 			if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
 				prev = prev->next;
@@ -187,7 +187,7 @@
 			prev = var;
 		}
 	}
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 
 	return var;
 }
@@ -217,15 +217,15 @@
 	ast_cli(a->fd, FORMAT, "Type", "Description",       "Devicestate", "Indications", "Transfer");
 	ast_cli(a->fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
 	
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, cl, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, cl, list) {
 		ast_cli(a->fd, FORMAT, cl->tech->type, cl->tech->description,
 			(cl->tech->devicestate) ? "yes" : "no",
 			(cl->tech->indicate) ? "yes" : "no",
 			(cl->tech->transfer) ? "yes" : "no");
 		count_chan++;
 	}
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 
 	ast_cli(a->fd, "----------\n%d channel drivers registered.\n", count_chan);
 
@@ -246,12 +246,14 @@
 
 	wordlen = strlen(a->word);
 
-	AST_LIST_TRAVERSE(&backends, cl, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, cl, list) {
 		if (!strncasecmp(a->word, cl->tech->type, wordlen) && ++which > a->n) {
 			ret = ast_strdup(cl->tech->type);
 			break;
 		}
 	}
+	AST_RWLIST_UNLOCK(&backends);
 	
 	return ret;
 }
@@ -275,15 +277,15 @@
 	if (a->argc != 4)
 		return CLI_SHOWUSAGE;
 	
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, cl, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, cl, list) {
 		if (!strncasecmp(cl->tech->type, a->argv[3], strlen(cl->tech->type)))
 			break;
 	}
 
 	if (!cl) {
 		ast_cli(a->fd, "\n%s is not a registered channel driver.\n", a->argv[3]);
-		AST_LIST_UNLOCK(&backends);
+		AST_RWLIST_UNLOCK(&backends);
 		return CLI_FAILURE;
 	}
 
@@ -311,7 +313,7 @@
 		
 	);
 
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 
 	return CLI_SUCCESS;
 }
@@ -416,8 +418,8 @@
 	struct chanlist *chan;
 	int res = 0;
 
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, chan, list) {
+	AST_RWLIST_WRLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, chan, list) {
 		if (!strcasecmp(tech->type, chan->tech->type)) {
 			ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
 			res = -1;
@@ -439,7 +441,7 @@
 	ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
 
 return_unlock:
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 
 	return res;
 }
@@ -451,8 +453,8 @@
 
 	ast_debug(1, "Unregistering channel type '%s'\n", tech->type);
 
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
+	AST_RWLIST_WRLOCK(&backends);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
 		if (chan->tech == tech) {
 			AST_LIST_REMOVE_CURRENT(list);
 			ast_free(chan);
@@ -460,8 +462,8 @@
 			break;	
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&backends);
 }
 
 /*! \brief Get handle to channel driver based on name */
@@ -470,14 +472,14 @@
 	struct chanlist *chanls;
 	const struct ast_channel_tech *ret = NULL;
 
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, chanls, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, chanls, list) {
 		if (!strcasecmp(name, chanls->tech->type)) {
 			ret = chanls->tech;
 			break;
 		}
 	}
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 	
 	return ret;
 }
@@ -3159,8 +3161,8 @@
 		cause = &foo;
 	*cause = AST_CAUSE_NOTDEFINED;
 
-	AST_LIST_LOCK(&backends);
-	AST_LIST_TRAVERSE(&backends, chan, list) {
+	AST_RWLIST_RDLOCK(&backends);
+	AST_RWLIST_TRAVERSE(&backends, chan, list) {
 		if (strcasecmp(type, chan->tech->type))
 			continue;
 
@@ -3170,10 +3172,10 @@
 		if (res < 0) {
 			ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format);
 			*cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
-			AST_LIST_UNLOCK(&backends);
+			AST_RWLIST_UNLOCK(&backends);
 			return NULL;
 		}
-		AST_LIST_UNLOCK(&backends);
+		AST_RWLIST_UNLOCK(&backends);
 		if (!chan->tech->requester)
 			return NULL;
 		
@@ -3183,7 +3185,7 @@
 		/* no need to generate a Newchannel event here; it is done in the channel_alloc call */
 		return c;
 	}
-	AST_LIST_UNLOCK(&backends);
+	AST_RWLIST_UNLOCK(&backends);
 
 	ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
 	*cause = AST_CAUSE_NOSUCHDRIVER;




More information about the asterisk-commits mailing list