[svn-commits] seanbright: branch seanbright/cdr-tds-conversion r126055 - /team/seanbright/c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jun 27 16:36:36 CDT 2008


Author: seanbright
Date: Fri Jun 27 16:36:35 2008
New Revision: 126055

URL: http://svn.digium.com/view/asterisk?view=rev&rev=126055
Log:
Make this a global lock.  Makes life easier.

Modified:
    team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c

Modified: team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c?view=diff&rev=126055&r1=126054&r2=126055
==============================================================================
--- team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c (original)
+++ team/seanbright/cdr-tds-conversion/cdr/cdr_tds.c Fri Jun 27 16:36:35 2008
@@ -91,8 +91,9 @@
 	);
 	DBPROCESS *dbproc;
 	unsigned int connected:1;
-	ast_mutex_t lock;
 };
+
+AST_MUTEX_DEFINE_STATIC(tds_lock);
 
 static struct cdr_tds_config *settings;
 
@@ -110,7 +111,7 @@
 	char *accountcode, *src, *dst, *dcontext, *clid, *channel, *dstchannel, *lastapp, *lastdata, *uniqueid;
 	RETCODE erc;
 
-	ast_mutex_lock(&settings->lock);
+	ast_mutex_lock(&tds_lock);
 
 	memset(sqlcmd, 0, 2048);
 
@@ -133,7 +134,7 @@
 	if (!settings->connected) {
 		if (mssql_connect()) {
 			/* Connect failed */
-			ast_mutex_unlock(&settings->lock);
+			ast_mutex_unlock(&tds_lock);
 			return -1;
 		}
 	}
@@ -212,7 +213,7 @@
 
 	if (erc == FAIL) {
 		ast_log(LOG_ERROR, "Failed to build query\n");
-		ast_mutex_unlock(&settings->lock);
+		ast_mutex_unlock(&tds_lock);
 		return -1;
 	}
 
@@ -220,7 +221,7 @@
 
 	if (erc == FAIL) {
 		ast_log(LOG_ERROR, "Failed to send query\n");
-		ast_mutex_unlock(&settings->lock);
+		ast_mutex_unlock(&tds_lock);
 		return -1;
 	}
 
@@ -230,7 +231,7 @@
 		while (dbnextrow(settings->dbproc) != NO_MORE_ROWS);
 	}
 
-	ast_mutex_unlock(&settings->lock);
+	ast_mutex_unlock(&tds_lock);
 
 	return 0;
 }
@@ -337,7 +338,6 @@
 		return;
 	}
 
-	ast_mutex_destroy(&settings->lock);
 	ast_string_field_free_memory(settings);
 	ast_free(settings);
 }
@@ -345,9 +345,9 @@
 static int tds_unload_module(void)
 {
 	if (settings) {
-		ast_mutex_lock(&settings->lock);
+		ast_mutex_lock(&tds_lock);
 		mssql_disconnect();
-		ast_mutex_unlock(&settings->lock);
+		ast_mutex_unlock(&tds_lock);
 	}
 
 	tds_config_free();
@@ -395,6 +395,8 @@
 		return 0;
 	}
 
+	ast_mutex_lock(&tds_lock);
+
 	if (reload) {
 		/* This will clear out all of our existing settings */
 		ast_string_field_init(settings, 0);
@@ -402,6 +404,7 @@
 		if (dbinit() == FAIL) {
 			ast_log(LOG_ERROR, "Failed to initialize db-lib\n");
 			ast_config_destroy(cfg);
+			ast_mutex_unlock(&tds_lock);
 			return 0;
 		}
 
@@ -415,15 +418,12 @@
 				ast_free(settings);
 				settings = NULL;
 			}
+			dbexit();
 			ast_config_destroy(cfg);
-			dbexit();
+			ast_mutex_unlock(&tds_lock);
 			return 0;
 		}
-
-		ast_mutex_init(&settings->lock);
-	}
-
-	ast_mutex_lock(&settings->lock);
+	}
 
 	ptr = ast_variable_retrieve(cfg, "global", "hostname");
 	if (ptr) {
@@ -485,16 +485,15 @@
 
 	if (mssql_connect()) {
 		/* We failed to connect (mssql_connect takes care of logging it) */
-		ast_mutex_unlock(&settings->lock);
-		return 0;
-	}
-
-	ast_mutex_unlock(&settings->lock);
+		goto failed;
+	}
+
+	ast_mutex_unlock(&tds_lock);
 
 	return 1;
 
 failed:
-	ast_mutex_unlock(&settings->lock);
+	ast_mutex_unlock(&tds_lock);
 	tds_config_free();
 	ast_config_destroy(cfg);
 	if (!reload) {




More information about the svn-commits mailing list