提交 417bbd15 authored 作者: Rupa Schomaker's avatar Rupa Schomaker

add mutex around odbc calls


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11609 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 f8d0521b
...@@ -120,6 +120,7 @@ static struct { ...@@ -120,6 +120,7 @@ static struct {
char *dbname; char *dbname;
char *odbc_dsn; char *odbc_dsn;
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_mutex_t *db_mutex;
switch_odbc_handle_t *master_odbc; switch_odbc_handle_t *master_odbc;
switch_hash_t *profile_hash; switch_hash_t *profile_hash;
profile_t *default_profile; profile_t *default_profile;
...@@ -155,7 +156,7 @@ static char *get_bridge_data(const char *dialed_number, lcr_route cur_route) ...@@ -155,7 +156,7 @@ static char *get_bridge_data(const char *dialed_number, lcr_route cur_route)
, destination_number, cur_route->suffix, cur_route->gw_suffix); , destination_number, cur_route->suffix, cur_route->gw_suffix);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Returning Dialstring %s\n", data); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Returning Dialstring %s\n", data);
switch_safe_free(orig_destination_number); switch_safe_free(orig_destination_number); /* don't need to free destination_number */
return data; return data;
} }
...@@ -243,7 +244,7 @@ static char *string_digitsonly(const char *str) ...@@ -243,7 +244,7 @@ static char *string_digitsonly(const char *str)
p = (char *)str; p = (char *)str;
len = strlen(str); len = strlen(str);
switch_zmalloc(newstr, len+1); /* worst case, same string */ switch_zmalloc(newstr, len+1);
np = newstr; np = newstr;
while(*p) { while(*p) {
...@@ -260,15 +261,19 @@ static char *string_digitsonly(const char *str) ...@@ -260,15 +261,19 @@ static char *string_digitsonly(const char *str)
static switch_bool_t lcr_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata) static switch_bool_t lcr_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata)
{ {
switch_bool_t retval = SWITCH_FALSE;
switch_mutex_lock(globals.db_mutex);
if (globals.odbc_dsn) { if (globals.odbc_dsn) {
if(switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata) if(switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata)
== SWITCH_ODBC_FAIL) { == SWITCH_ODBC_FAIL) {
return SWITCH_FALSE; retval = SWITCH_FALSE;
} else { } else {
return SWITCH_TRUE; retval = SWITCH_TRUE;
} }
} }
return SWITCH_FALSE; switch_mutex_unlock(globals.db_mutex);
return retval;
} }
int route_add_callback(void *pArg, int argc, char **argv, char **columnNames) int route_add_callback(void *pArg, int argc, char **argv, char **columnNames)
...@@ -766,6 +771,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lcr_load) ...@@ -766,6 +771,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lcr_load)
if (switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool) != SWITCH_STATUS_SUCCESS) { if (switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize mutex\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize mutex\n");
} }
if (switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_UNNESTED, globals.pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to initialize db_mutex\n");
}
if(set_db_random() == SWITCH_TRUE) { if(set_db_random() == SWITCH_TRUE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Database RANDOM function set to %s\n", db_random); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Database RANDOM function set to %s\n", db_random);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论