[svn-commits] trunk - r7728 in /trunk: image.c include/asterisk/image.h

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jan 3 02:40:58 CST 2006


Author: oej
Date: Tue Jan  3 02:40:55 2006
New Revision: 7728

URL: http://svn.digium.com/view/asterisk?rev=7728&view=rev
Log:
Bug #6118: Clean up list handling in image.c (drumkilla)

Modified:
    trunk/image.c
    trunk/include/asterisk/image.h

Modified: trunk/image.c
URL: http://svn.digium.com/view/asterisk/trunk/image.c?rev=7728&r1=7727&r2=7728&view=diff
==============================================================================
--- trunk/image.c (original)
+++ trunk/image.c Tue Jan  3 02:40:55 2006
@@ -46,37 +46,31 @@
 #include "asterisk/cli.h"
 #include "asterisk/lock.h"
 
-static struct ast_imager *list;
-AST_MUTEX_DEFINE_STATIC(listlock);
+static AST_LIST_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_mutex_lock(&listlock);
-	img->next = list;
-	list = img;
-	ast_mutex_unlock(&listlock);
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_INSERT_HEAD(&imagers, img, list);
+	AST_LIST_UNLOCK(&imagers);
 	return 0;
 }
 
 void ast_image_unregister(struct ast_imager *img)
 {
-	struct ast_imager *i, *prev = NULL;
-	ast_mutex_lock(&listlock);
-	i = list;
-	while(i) {
+	struct ast_imager *i;
+	
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {	
 		if (i == img) {
-			if (prev) 
-				prev->next = i->next;
-			else
-				list = i->next;
+			AST_LIST_REMOVE_CURRENT(&imagers, list);
 			break;
 		}
-		prev = i;
-		i = i->next;
-	}
-	ast_mutex_unlock(&listlock);
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+	AST_LIST_UNLOCK(&imagers);
 	if (i && (option_verbose > 1))
 		ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
 }
@@ -125,11 +119,9 @@
 	int fd;
 	int len=0;
 	struct ast_frame *f = NULL;
-#if 0 /* We need to have some sort of read-only lock */
-	ast_mutex_lock(&listlock);
-#endif	
-	i = list;
-	while(!found && i) {
+	
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_TRAVERSE(&imagers, i, list) {
 		if (i->format & format) {
 			char *stringp=NULL;
 			strncpy(tmp, i->exts, sizeof(tmp)-1);
@@ -149,8 +141,10 @@
 				e = strsep(&stringp, "|");
 			}
 		}
-		i = i->next;
-	}
+		if (found)
+			break;	
+	}
+
 	if (found) {
 		fd = open(buf, O_RDONLY);
 		if (fd > -1) {
@@ -165,9 +159,9 @@
 			ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
 	} else
 		ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
-#if 0
-	ast_mutex_unlock(&listlock);
-#endif	
+	
+	AST_LIST_UNLOCK(&imagers);
+	
 	return f;
 }
 
@@ -194,11 +188,8 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
-	i = list;
-	while(i) {
+	AST_LIST_TRAVERSE(&imagers, i, list)
 		ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
-		i = i->next;
-	};
 	return RESULT_SUCCESS;
 }
 

Modified: trunk/include/asterisk/image.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/image.h?rev=7728&r1=7727&r2=7728&view=diff
==============================================================================
--- trunk/include/asterisk/image.h (original)
+++ trunk/include/asterisk/image.h Tue Jan  3 02:40:55 2006
@@ -40,7 +40,7 @@
 	/*! Returns length written */
 	int (*write_image)(int fd, struct ast_frame *frame); 	
 	/*! For linked list */
-	struct ast_imager *next;
+	AST_LIST_ENTRY(ast_imager) list;
 };
 
 /*! Check for image support on a channel */



More information about the svn-commits mailing list