Index: res_config_mysql.c =================================================================== RCS file: /usr/cvsroot/asterisk-addons/res_config_mysql.c,v retrieving revision 1.9 diff -u -r1.9 res_config_mysql.c --- res_config_mysql.c 26 Aug 2005 20:34:41 -0000 1.9 +++ res_config_mysql.c 7 Oct 2005 17:14:02 -0000 @@ -8,6 +8,8 @@ * * res_config_mysql.c * + * v2.0 - (10-07-05) - mutex_lock fixes (bug #4973, comment #0034602) + * * v1.9 - (08-19-05) - Added support to correctly honor the family database specified * in extconfig.conf (bug #4973) * @@ -127,7 +129,6 @@ return NULL; } - ast_mutex_lock(&mysql_lock); if(mysql_real_query(&mysql, sql, strlen(sql))) { ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n"); ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql); @@ -238,7 +239,6 @@ return NULL; } - ast_mutex_lock(&mysql_lock); if(mysql_real_query(&mysql, sql, strlen(sql))) { ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n"); ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql); @@ -321,13 +321,12 @@ return -1; } - ast_mutex_lock(&mysql_lock); if(mysql_real_query(&mysql, sql, strlen(sql))) { ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n"); ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql); ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql)); ast_mutex_unlock(&mysql_lock); - return -1; + return -1; } numrows = mysql_affected_rows(&mysql); @@ -448,6 +447,8 @@ } ast_cli_register(&cli_realtime_mysql_status); + ast_mutex_unlock(&mysql_lock); + return 0; } @@ -587,7 +588,9 @@ else ast_copy_string(my_database, database, sizeof(my_database)); + /* Create the lock here. This lock will remain if mysql_reconnect returns true. */ ast_mutex_lock(&mysql_lock); + if((!connected) && (dbhost || dbsock) && dbuser && dbpass && my_database) { if(!mysql_init(&mysql)) { ast_log(LOG_WARNING, "MySQL RealTime: Insufficient memory to allocate MySQL resource.\n"); @@ -599,7 +602,6 @@ ast_log(LOG_DEBUG, "MySQL RealTime: Successfully connected to database.\n"); connected = 1; connect_time = time(NULL); - ast_mutex_unlock(&mysql_lock); return 1; } else { ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s. Check debug for more info.\n", dbname, dbhost); @@ -627,7 +629,6 @@ } ast_log(LOG_DEBUG, "MySQL RealTime: Everything is fine.\n"); - ast_mutex_unlock(&mysql_lock); return 1; } }