struct odbc_class *class = obj->parent;
obj->parent = NULL;
odbc_obj_disconnect(obj);
- ast_mutex_destroy(&obj->lock);
ao2_ref(class, -1);
}
}
/* 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)) {
AST_RWLIST_RDLOCK(&(tableptr->columns));
break;
} while (1);
- ast_mutex_unlock(&obj->lock);
+ ao2_unlock(obj);
AST_RWLIST_UNLOCK(&odbc_tables);
int attempt;
SQLHSTMT stmt;
- ast_mutex_lock(&obj->lock);
+ ao2_lock(obj);
for (attempt = 0; attempt < 2; attempt++) {
stmt = exec_cb(obj, data);
}
}
- ast_mutex_unlock(&obj->lock);
+ ao2_unlock(obj);
return stmt;
}
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
}
}
- ast_mutex_unlock(&obj->lock);
+ ao2_unlock(obj);
return stmt;
}
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)) {
obj->last_used = ast_tvnow();
}
- ast_mutex_unlock(&obj->lock);
+ ao2_unlock(obj);
return res;
}
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(¤t->lock);
+ ao2_lock(current);
#ifdef DEBUG_THREADS
ast_cli(a->fd, " - Connection %d: %s (%s:%d %s)\n", ++count,
current->used ? "in use" :
current->used ? "in use" :
current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
#endif
- ast_mutex_unlock(¤t->lock);
+ ao2_unlock(current);
ao2_ref(current, -1);
}
ao2_iterator_destroy(&aoi2);
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;
}
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;
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. */
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;
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);
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;
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);
#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);
continue;
}
- ast_mutex_lock(¤t->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(¤t->lock);
+ ao2_unlock(current);
if (class->haspool) {
ast_data_add_int(data_odbc_connection, "number", ++count);