[asterisk-addons-commits] tilghman: trunk r719 - /trunk/cdr/cdr_addon_mysql.c

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Thu Jan 8 15:55:13 CST 2009


Author: tilghman
Date: Thu Jan  8 15:55:12 2009
New Revision: 719

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=719
Log:
Prevent a possible race between a reload event and logging a CDR

Modified:
    trunk/cdr/cdr_addon_mysql.c

Modified: trunk/cdr/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr/cdr_addon_mysql.c?view=diff&rev=719&r1=718&r2=719
==============================================================================
--- trunk/cdr/cdr_addon_mysql.c (original)
+++ trunk/cdr/cdr_addon_mysql.c Thu Jan  8 15:55:12 2009
@@ -312,7 +312,7 @@
 	return 0;
 }
 
-static int my_unload_module(void)
+static int my_unload_module(int reload)
 { 
 	struct unload_string *us;
 	struct column *entry;
@@ -332,11 +332,15 @@
 	}
 	AST_LIST_UNLOCK(&unload_strings);
 
-	AST_RWLIST_WRLOCK(&columns);
+	if (!reload) {
+		AST_RWLIST_WRLOCK(&columns);
+	}
 	while ((entry = AST_RWLIST_REMOVE_HEAD(&columns, list))) {
 		ast_free(entry);
 	}
-	AST_RWLIST_UNLOCK(&columns);
+	if (!reload) {
+		AST_RWLIST_UNLOCK(&columns);
+	}
 
 	dbport = 0;
 	ast_cdr_unregister(name);
@@ -405,12 +409,17 @@
 	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
 		return AST_MODULE_LOAD_SUCCESS;
 
-	if (reload)
-		my_unload_module();
+	if (reload) {
+		AST_RWLIST_WRLOCK(&columns);
+		my_unload_module(1);
+	}
 
 	var = ast_variable_browse(cfg, "global");
 	if (!var) {
 		/* nothing configured */
+		if (reload) {
+			AST_RWLIST_UNLOCK(&columns);
+		}
 		return AST_MODULE_LOAD_SUCCESS;
 	}
 
@@ -439,11 +448,17 @@
 	}
 
 	if (res < 0) {
+		if (reload) {
+			AST_RWLIST_UNLOCK(&columns);
+		}
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
 	/* Check for any aliases */
-	AST_RWLIST_WRLOCK(&columns);
+	if (!reload) {
+		/* Lock, if not already */
+		AST_RWLIST_WRLOCK(&columns);
+	}
 	while ((entry = AST_LIST_REMOVE_HEAD(&columns, list))) {
 		ast_free(entry);
 	}
@@ -601,7 +616,7 @@
 
 static int unload_module(void)
 {
-	return my_unload_module();
+	return my_unload_module(0);
 }
 
 static int reload(void)




More information about the asterisk-addons-commits mailing list