[asterisk-commits] file: trunk r52332 - in /trunk/main: file.c image.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Jan 26 15:55:07 MST 2007


Author: file
Date: Fri Jan 26 16:55:06 2007
New Revision: 52332

URL: http://svn.digium.com/view/asterisk?view=rev&rev=52332
Log:
Convert some more stuff to read/write lists.

Modified:
    trunk/main/file.c
    trunk/main/image.c

Modified: trunk/main/file.c
URL: http://svn.digium.com/view/asterisk/trunk/main/file.c?view=diff&rev=52332&r1=52331&r2=52332
==============================================================================
--- trunk/main/file.c (original)
+++ trunk/main/file.c Fri Jan 26 16:55:06 2007
@@ -63,25 +63,22 @@
  */
 int ast_language_is_prefix = 1;
 
-static AST_LIST_HEAD_STATIC(formats, ast_format);
+static AST_RWLIST_HEAD_STATIC(formats, ast_format);
 
 int __ast_format_register(const struct ast_format *f, struct ast_module *mod)
 {
 	struct ast_format *tmp;
 
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return -1;
-	}
-	AST_LIST_TRAVERSE(&formats, tmp, list) {
+	AST_RWLIST_WRLOCK(&formats);
+	AST_RWLIST_TRAVERSE(&formats, tmp, list) {
 		if (!strcasecmp(f->name, tmp->name)) {
-			AST_LIST_UNLOCK(&formats);
+			AST_RWLIST_UNLOCK(&formats);
 			ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
 			return -1;
 		}
 	}
 	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
-		AST_LIST_UNLOCK(&formats);
+		AST_RWLIST_UNLOCK(&formats);
 		return -1;
 	}
 	*tmp = *f;
@@ -98,8 +95,8 @@
 	
 	memset(&tmp->list, 0, sizeof(tmp->list));
 
-	AST_LIST_INSERT_HEAD(&formats, tmp, list);
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
+	AST_RWLIST_UNLOCK(&formats);
 	if (option_verbose > 1)
 		ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", f->name, f->exts);
 
@@ -111,19 +108,16 @@
 	struct ast_format *tmp;
 	int res = -1;
 
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return -1;
-	}
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
+	AST_RWLIST_WRLOCK(&formats);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
 		if (!strcasecmp(name, tmp->name)) {
-			AST_LIST_REMOVE_CURRENT(&formats, list);
+			AST_RWLIST_REMOVE_CURRENT(&formats, list);
 			free(tmp);
 			res = 0;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_TRAVERSE_SAFE_END
+	AST_RWLIST_UNLOCK(&formats);
 
 	if (!res) {
 		if (option_verbose > 1)
@@ -352,12 +346,9 @@
 	struct ast_format *f;
 	int res = (action == ACTION_EXISTS) ? 0 : -1;
 
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return res;
-	}
+	AST_RWLIST_RDLOCK(&formats);
 	/* Check for a specific format */
-	AST_LIST_TRAVERSE(&formats, f, list) {
+	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		char *stringp, *ext = NULL;
 
 		if (fmt && !exts_compare(f->exts, fmt))
@@ -456,7 +447,7 @@
 			free(fn);
 		}
 	}
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_UNLOCK(&formats);
 	return res;
 }
 
@@ -815,12 +806,9 @@
 	struct ast_filestream *fs = NULL;
 	char *fn;
 
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return NULL;
-	}
-
-	AST_LIST_TRAVERSE(&formats, f, list) {
+	AST_RWLIST_RDLOCK(&formats);
+
+	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		fs = NULL;
 		if (!exts_compare(f->exts, type))
 			continue;
@@ -848,7 +836,7 @@
 		break;
 	}
 
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_UNLOCK(&formats);
 	if (!fs) 
 		ast_log(LOG_WARNING, "No such format '%s'\n", type);
 
@@ -866,10 +854,7 @@
 	size_t size = 0;
 	int format_found = 0;
 
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return NULL;
-	}
+	AST_RWLIST_RDLOCK(&formats);
 
 	/* set the O_TRUNC flag if and only if there is no O_APPEND specified */
 	/* We really can't use O_APPEND as it will break WAV header updates */
@@ -884,7 +869,7 @@
 	/* XXX need to fix this - we should just do the fopen,
 	 * not open followed by fdopen()
 	 */
-	AST_LIST_TRAVERSE(&formats, f, list) {
+	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		char *fn, *orig_fn = NULL;
 		if (fs)
 			break;
@@ -974,7 +959,7 @@
 			free(fn);
 	}
 
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_UNLOCK(&formats);
 
 	if (!format_found)
 		ast_log(LOG_WARNING, "No such format '%s'\n", type);
@@ -1138,17 +1123,13 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	ast_cli(fd, FORMAT, "Format", "Name", "Extensions");
-	        
-	if (AST_LIST_LOCK(&formats)) {
-		ast_log(LOG_WARNING, "Unable to lock format list\n");
-		return -1;
-	}
-
-	AST_LIST_TRAVERSE(&formats, f, list) {
+
+	AST_RWLIST_RDLOCK(&formats);
+	AST_RWLIST_TRAVERSE(&formats, f, list) {
 		ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
 		count_fmt++;
 	}
-	AST_LIST_UNLOCK(&formats);
+	AST_RWLIST_UNLOCK(&formats);
 	ast_cli(fd, "%d file formats registered.\n", count_fmt);
 	return RESULT_SUCCESS;
 #undef FORMAT

Modified: trunk/main/image.c
URL: http://svn.digium.com/view/asterisk/trunk/main/image.c?view=diff&rev=52332&r1=52331&r2=52332
==============================================================================
--- trunk/main/image.c (original)
+++ trunk/main/image.c Fri Jan 26 16:55:06 2007
@@ -47,15 +47,15 @@
 #include "asterisk/lock.h"
 
 /* XXX Why don't we just use the formats struct for this? */
-static AST_LIST_HEAD_STATIC(imagers, ast_imager);
+static AST_RWLIST_HEAD_STATIC(imagers, ast_imager);
 
 int ast_image_register(struct ast_imager *img)
 {
 	if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
-	AST_LIST_LOCK(&imagers);
-	AST_LIST_INSERT_HEAD(&imagers, img, list);
-	AST_LIST_UNLOCK(&imagers);
+	AST_RWLIST_WRLOCK(&imagers);
+	AST_RWLIST_INSERT_HEAD(&imagers, img, list);
+	AST_RWLIST_UNLOCK(&imagers);
 	return 0;
 }
 
@@ -63,15 +63,15 @@
 {
 	struct ast_imager *i;
 	
-	AST_LIST_LOCK(&imagers);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {	
+	AST_RWLIST_WRLOCK(&imagers);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {	
 		if (i == img) {
-			AST_LIST_REMOVE_CURRENT(&imagers, list);
+			AST_RWLIST_REMOVE_CURRENT(&imagers, list);
 			break;
 		}
 	}
-	AST_LIST_TRAVERSE_SAFE_END
-	AST_LIST_UNLOCK(&imagers);
+	AST_RWLIST_TRAVERSE_SAFE_END
+	AST_RWLIST_UNLOCK(&imagers);
 	if (i && (option_verbose > 1))
 		ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
 }
@@ -121,8 +121,8 @@
 	int len=0;
 	struct ast_frame *f = NULL;
 	
-	AST_LIST_LOCK(&imagers);
-	AST_LIST_TRAVERSE(&imagers, i, list) {
+	AST_RWLIST_RDLOCK(&imagers);
+	AST_RWLIST_TRAVERSE(&imagers, i, list) {
 		if (i->format & format) {
 			char *stringp=NULL;
 			ast_copy_string(tmp, i->exts, sizeof(tmp));
@@ -161,7 +161,7 @@
 	} else
 		ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
 	
-	AST_LIST_UNLOCK(&imagers);
+	AST_RWLIST_UNLOCK(&imagers);
 	
 	return f;
 }
@@ -188,8 +188,11 @@
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
-	AST_LIST_TRAVERSE(&imagers, i, list)
+	AST_RWLIST_RDLOCK(&imagers);
+	AST_RWLIST_TRAVERSE(&imagers, i, list) {
 		ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
+	}
+	AST_RWLIST_UNLOCK(&imagers);
 	return RESULT_SUCCESS;
 }
 



More information about the asterisk-commits mailing list