Index: res/res_odbc.c =================================================================== --- res/res_odbc.c (revision 117657) +++ res/res_odbc.c (working copy) @@ -107,6 +107,7 @@ int attempt; SQLHSTMT stmt; + ast_mutex_lock(&obj->lock); for (attempt = 0; attempt < 2; attempt++) { stmt = exec_cb(obj, data); @@ -120,6 +121,7 @@ odbc_obj_connect(obj); } } + ast_mutex_unlock(&obj->lock); return stmt; } @@ -132,6 +134,7 @@ unsigned char state[10], diagnostic[256]; SQLHSTMT stmt; + ast_mutex_lock(&obj->lock); for (attempt = 0; attempt < 2; attempt++) { /* This prepare callback may do more than just prepare -- it may also * bind parameters, bind results, etc. The real key, here, is that @@ -172,7 +175,7 @@ } else if (attempt == 0) ast_odbc_sanity_check(obj); } - + ast_mutex_unlock(&obj->lock); return stmt; } @@ -183,6 +186,7 @@ SQLSMALLINT diagbytes=0; unsigned char state[10], diagnostic[256]; + ast_mutex_lock(&obj->lock); res = SQLExecute(stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) { if (res == SQL_ERROR) { @@ -198,7 +202,9 @@ } } else obj->last_used = ast_tvnow(); - + + ast_mutex_unlock(&obj->lock); + return res; } @@ -417,16 +423,22 @@ 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); ast_cli(a->fd, " - Connection %d: %s\n", ++count, current->used ? "in use" : current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected"); + ast_mutex_unlock(¤t->lock); ao2_ref(current, -1); } } else { /* Should only ever be one of these */ struct ao2_iterator aoi2 = ao2_iterator_init(class->obj_container, 0); while ((current = ao2_iterator_next(&aoi2))) { - ast_cli(a->fd, " Pooled: No\n Connected: %s\n", current->up && ast_odbc_sanity_check(current) ? "Yes" : "No"); + ast_mutex_lock(¤t->lock); + ast_cli(a->fd, " Pooled: No\n Status: %s\n", + current->used ? "In use" : + current->up && ast_odbc_sanity_check(current) ? "Connected" : "Disconnected"); + ast_mutex_unlock(¤t->lock); ao2_ref(current, -1); } }