[asterisk-commits] file: trunk r69130 - in /trunk: funcs/ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jun 13 11:23:13 MST 2007


Author: file
Date: Wed Jun 13 13:23:12 2007
New Revision: 69130

URL: http://svn.digium.com/view/asterisk?view=rev&rev=69130
Log:
Use read/write lock based lists for group counting.

Modified:
    trunk/funcs/func_groupcount.c
    trunk/include/asterisk/app.h
    trunk/main/app.c
    trunk/main/cli.c

Modified: trunk/funcs/func_groupcount.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_groupcount.c?view=diff&rev=69130&r1=69129&r2=69130
==============================================================================
--- trunk/funcs/func_groupcount.c (original)
+++ trunk/funcs/func_groupcount.c Wed Jun 13 13:23:12 2007
@@ -100,7 +100,7 @@
 {
 	struct ast_group_info *gi = NULL;
 	
-	ast_app_group_list_lock();
+	ast_app_group_list_rdlock();
 	
 	gi = ast_app_group_list_head();
 	while (gi) {
@@ -158,7 +158,7 @@
 	if (!chan)
 		return -1;
 
-	ast_app_group_list_lock();
+	ast_app_group_list_rdlock();
 
 	gi = ast_app_group_list_head();
 	while (gi) {

Modified: trunk/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/app.h?view=diff&rev=69130&r1=69129&r2=69130
==============================================================================
--- trunk/include/asterisk/app.h (original)
+++ trunk/include/asterisk/app.h Wed Jun 13 13:23:12 2007
@@ -236,8 +236,11 @@
 /*! Update all group counting for a channel to a new one */
 int ast_app_group_update(struct ast_channel *oldchan, struct ast_channel *newchan);
 
-/*! Lock the group count list */
-int ast_app_group_list_lock(void);
+/*! Write Lock the group count list */
+int ast_app_group_list_wrlock(void);
+
+/*! Read Lock the group count list */
+int ast_app_group_list_rdlock(void);
 
 /*! Get the head of the group count list */
 struct ast_group_info *ast_app_group_list_head(void);

Modified: trunk/main/app.c
URL: http://svn.digium.com/view/asterisk/trunk/main/app.c?view=diff&rev=69130&r1=69129&r2=69130
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Wed Jun 13 13:23:12 2007
@@ -53,7 +53,7 @@
 
 #define MAX_OTHER_FORMATS 10
 
-static AST_LIST_HEAD_STATIC(groups, ast_group_info);
+static AST_RWLIST_HEAD_STATIC(groups, ast_group_info);
 
 /*!
  * \brief This function presents a dialtone and reads an extension into 'collect' 
@@ -874,15 +874,15 @@
 	if (!ast_strlen_zero(category))
 		len += strlen(category) + 1;
 	
-	AST_LIST_LOCK(&groups);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
+	AST_RWLIST_WRLOCK(&groups);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
 		if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
-			AST_LIST_REMOVE_CURRENT(&groups, list);
+			AST_RWLIST_REMOVE_CURRENT(&groups, list);
 			free(gi);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END
+	AST_RWLIST_TRAVERSE_SAFE_END
 
 	if ((gi = calloc(1, len))) {
 		gi->chan = chan;
@@ -892,12 +892,12 @@
 			gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
 			strcpy(gi->category, category);
 		}
-		AST_LIST_INSERT_TAIL(&groups, gi, list);
+		AST_RWLIST_INSERT_TAIL(&groups, gi, list);
 	} else {
 		res = -1;
 	}
 	
-	AST_LIST_UNLOCK(&groups);
+	AST_RWLIST_UNLOCK(&groups);
 	
 	return res;
 }
@@ -910,12 +910,12 @@
 	if (ast_strlen_zero(group))
 		return 0;
 	
-	AST_LIST_LOCK(&groups);
-	AST_LIST_TRAVERSE(&groups, gi, list) {
+	AST_RWLIST_RDLOCK(&groups);
+	AST_RWLIST_TRAVERSE(&groups, gi, list) {
 		if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category)))
 			count++;
 	}
-	AST_LIST_UNLOCK(&groups);
+	AST_RWLIST_UNLOCK(&groups);
 
 	return count;
 }
@@ -933,12 +933,12 @@
 	if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
 		return 0;
 
-	AST_LIST_LOCK(&groups);
-	AST_LIST_TRAVERSE(&groups, gi, list) {
+	AST_RWLIST_RDLOCK(&groups);
+	AST_RWLIST_TRAVERSE(&groups, gi, list) {
 		if (!regexec(&regexbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category)))
 			count++;
 	}
-	AST_LIST_UNLOCK(&groups);
+	AST_RWLIST_UNLOCK(&groups);
 
 	regfree(&regexbuf);
 
@@ -949,12 +949,12 @@
 {
 	struct ast_group_info *gi = NULL;
 
-	AST_LIST_LOCK(&groups);
-	AST_LIST_TRAVERSE(&groups, gi, list) {
+	AST_RWLIST_WRLOCK(&groups);
+	AST_RWLIST_TRAVERSE(&groups, gi, list) {
 		if (gi->chan == old)
 			gi->chan = new;
 	}
-	AST_LIST_UNLOCK(&groups);
+	AST_RWLIST_UNLOCK(&groups);
 
 	return 0;
 }
@@ -963,32 +963,37 @@
 {
 	struct ast_group_info *gi = NULL;
 	
-	AST_LIST_LOCK(&groups);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
+	AST_RWLIST_WRLOCK(&groups);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
 		if (gi->chan == chan) {
-			AST_LIST_REMOVE_CURRENT(&groups, list);
+			AST_RWLIST_REMOVE_CURRENT(&groups, list);
 			ast_free(gi);
 		}
 	}
-        AST_LIST_TRAVERSE_SAFE_END
-	AST_LIST_UNLOCK(&groups);
+        AST_RWLIST_TRAVERSE_SAFE_END
+	AST_RWLIST_UNLOCK(&groups);
 	
 	return 0;
 }
 
-int ast_app_group_list_lock(void)
-{
-	return AST_LIST_LOCK(&groups);
+int ast_app_group_list_wrlock(void)
+{
+	return AST_RWLIST_WRLOCK(&groups);
+}
+
+int ast_app_group_list_rdlock(void)
+{
+	return AST_RWLIST_RDLOCK(&groups);
 }
 
 struct ast_group_info *ast_app_group_list_head(void)
 {
-	return AST_LIST_FIRST(&groups);
+	return AST_RWLIST_FIRST(&groups);
 }
 
 int ast_app_group_list_unlock(void)
 {
-	return AST_LIST_UNLOCK(&groups);
+	return AST_RWLIST_UNLOCK(&groups);
 }
 
 unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)

Modified: trunk/main/cli.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cli.c?view=diff&rev=69130&r1=69129&r2=69130
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Wed Jun 13 13:23:12 2007
@@ -923,7 +923,7 @@
 
 	ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
 
-	ast_app_group_list_lock();
+	ast_app_group_list_rdlock();
 	
 	gi = ast_app_group_list_head();
 	while (gi) {



More information about the asterisk-commits mailing list