[asterisk-commits] jrose: trunk r357051 - in /trunk: include/asterisk/res_odbc.h res/res_odbc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 27 13:55:19 CST 2012


Author: jrose
Date: Mon Feb 27 13:55:14 2012
New Revision: 357051

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357051
Log:
Converts locking for odbc containers from ast_mutex_lock to ao2_locks.


Modified:
    trunk/include/asterisk/res_odbc.h
    trunk/res/res_odbc.c

Modified: trunk/include/asterisk/res_odbc.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_odbc.h?view=diff&rev=357051&r1=357050&r2=357051
==============================================================================
--- trunk/include/asterisk/res_odbc.h (original)
+++ trunk/include/asterisk/res_odbc.h Mon Feb 27 13:55:14 2012
@@ -44,7 +44,6 @@
 
 /*! \brief ODBC container */
 struct odbc_obj {
-	ast_mutex_t lock;
 	SQLHDBC  con;                   /*!< ODBC Connection Handle */
 	struct odbc_class *parent;      /*!< Information about the connection is protected */
 	struct timeval last_used;       /*!< Used by idlecheck to determine if the connection should be renegotiated */

Modified: trunk/res/res_odbc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_odbc.c?view=diff&rev=357051&r1=357050&r2=357051
==============================================================================
--- trunk/res/res_odbc.c (original)
+++ trunk/res/res_odbc.c Mon Feb 27 13:55:14 2012
@@ -416,7 +416,6 @@
 	struct odbc_class *class = obj->parent;
 	obj->parent = NULL;
 	odbc_obj_disconnect(obj);
-	ast_mutex_destroy(&obj->lock);
 	ao2_ref(class, -1);
 }
 
@@ -473,7 +472,7 @@
 	}
 
 	/* Table structure not already cached; build it now. */
-	ast_mutex_lock(&obj->lock);
+	ao2_lock(obj);
 	do {
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -544,7 +543,7 @@
 		AST_RWLIST_RDLOCK(&(tableptr->columns));
 		break;
 	} while (1);
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 
 	AST_RWLIST_UNLOCK(&odbc_tables);
 
@@ -591,7 +590,7 @@
 	int attempt;
 	SQLHSTMT stmt;
 
-	ast_mutex_lock(&obj->lock);
+	ao2_lock(obj);
 
 	for (attempt = 0; attempt < 2; attempt++) {
 		stmt = exec_cb(obj, data);
@@ -609,7 +608,7 @@
 		}
 	}
 
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 
 	return stmt;
 }
@@ -622,7 +621,7 @@
 	unsigned char state[10], diagnostic[256];
 	SQLHSTMT stmt;
 
-	ast_mutex_lock(&obj->lock);
+	ao2_lock(obj);
 
 	for (attempt = 0; attempt < 2; attempt++) {
 		/* This prepare callback may do more than just prepare -- it may also
@@ -674,7 +673,7 @@
 		}
 	}
 
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 
 	return stmt;
 }
@@ -686,7 +685,7 @@
 	SQLSMALLINT diagbytes=0;
 	unsigned char state[10], diagnostic[256];
 
-	ast_mutex_lock(&obj->lock);
+	ao2_lock(obj);
 
 	res = SQLExecute(stmt);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
@@ -705,7 +704,7 @@
 		obj->last_used = ast_tvnow();
 	}
 
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 
 	return res;
 }
@@ -981,7 +980,7 @@
 				ast_cli(a->fd, "  Pooled: Yes\n  Limit:  %d\n  Connections in use: %d\n", class->limit, class->count);
 
 				while ((current = ao2_iterator_next(&aoi2))) {
-					ast_mutex_lock(&current->lock);
+					ao2_lock(current);
 #ifdef DEBUG_THREADS
 					ast_cli(a->fd, "    - Connection %d: %s (%s:%d %s)\n", ++count,
 						current->used ? "in use" :
@@ -992,7 +991,7 @@
 						current->used ? "in use" :
 						current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
 #endif
-					ast_mutex_unlock(&current->lock);
+					ao2_unlock(current);
 					ao2_ref(current, -1);
 				}
 				ao2_iterator_destroy(&aoi2);
@@ -1202,13 +1201,13 @@
 static int aoro2_obj_cb(void *vobj, void *arg, int flags)
 {
 	struct odbc_obj *obj = vobj;
-	ast_mutex_lock(&obj->lock);
+	ao2_lock(obj);
 	if ((arg == NO_TX && !obj->tx) || (arg == EOR_TX && !obj->used) || (arg == USE_TX && obj->tx && !obj->used)) {
 		obj->used = 1;
-		ast_mutex_unlock(&obj->lock);
+		ao2_unlock(obj);
 		return CMP_MATCH | CMP_STOP;
 	}
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 	return 0;
 }
 
@@ -1257,7 +1256,6 @@
 				return NULL;
 			}
 			ast_assert(ao2_ref(obj, 0) == 1);
-			ast_mutex_init(&obj->lock);
 			/* obj inherits the outstanding reference to class */
 			obj->parent = class;
 			class = NULL;
@@ -1286,7 +1284,7 @@
 			return NULL;
 		}
 
-		ast_mutex_lock(&obj->lock);
+		ao2_lock(obj);
 
 		if (ast_test_flag(&flags, RES_ODBC_INDEPENDENT_CONNECTION)) {
 			/* Ensure this connection has autocommit turned off. */
@@ -1312,7 +1310,6 @@
 				ast_debug(3, "Unable to allocate object\n");
 				return NULL;
 			}
-			ast_mutex_init(&obj->lock);
 			/* obj inherits the outstanding reference to class */
 			obj->parent = class;
 			class = NULL;
@@ -1331,7 +1328,7 @@
 			return NULL;
 		}
 
-		ast_mutex_lock(&obj->lock);
+		ao2_lock(obj);
 
 		if (SQLSetConnectAttr(obj->con, SQL_ATTR_AUTOCOMMIT, (void *)SQL_AUTOCOMMIT_OFF, 0) == SQL_ERROR) {
 			SQLGetDiagField(SQL_HANDLE_DBC, obj->con, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
@@ -1359,7 +1356,6 @@
 				ast_debug(3, "Unable to allocate object\n");
 				return NULL;
 			}
-			ast_mutex_init(&obj->lock);
 			/* obj inherits the outstanding reference to class */
 			obj->parent = class;
 			class = NULL;
@@ -1377,7 +1373,7 @@
 			return NULL;
 		}
 
-		ast_mutex_lock(&obj->lock);
+		ao2_lock(obj);
 
 		if (SQLSetConnectAttr(obj->con, SQL_ATTR_AUTOCOMMIT, (void *)SQL_AUTOCOMMIT_ON, 0) == SQL_ERROR) {
 			SQLGetDiagField(SQL_HANDLE_DBC, obj->con, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
@@ -1425,7 +1421,7 @@
 #endif
 
 	/* We had it locked because of the obj_connects we see here. */
-	ast_mutex_unlock(&obj->lock);
+	ao2_unlock(obj);
 
 	ast_assert(class == NULL);
 
@@ -1759,11 +1755,11 @@
 				continue;
 			}
 
-			ast_mutex_lock(&current->lock);
+			ao2_lock(current);
 			ast_data_add_str(data_odbc_connection, "status", current->used ? "in use" :
 					current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
 			ast_data_add_bool(data_odbc_connection, "transactional", current->tx);
-			ast_mutex_unlock(&current->lock);
+			ao2_unlock(current);
 
 			if (class->haspool) {
 				ast_data_add_int(data_odbc_connection, "number", ++count);




More information about the asterisk-commits mailing list