提交 8987e967 authored 作者: Anthony Minessale's avatar Anthony Minessale

add dedicated mutex for select based sql stuff

上级 42de0322
......@@ -3053,7 +3053,7 @@ static uint32_t sofia_profile_reg_count(sofia_profile_t *profile)
cb.buf = reg_count;
cb.len = sizeof(reg_count);
sql = switch_mprintf("select count(*) from sip_registrations where profile_name = '%q'", profile->name);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sql2str_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sql2str_callback, &cb);
free(sql);
return strtoul(reg_count, NULL, 10);
}
......@@ -3290,7 +3290,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
if (sql) {
stream->write_function(stream, "\nRegistrations:\n%s\n", line);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, show_reg_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, show_reg_callback, &cb);
switch_safe_free(sql);
stream->write_function(stream, "Total items returned: %d\n", cb.row_process);
......@@ -3572,7 +3572,7 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl
if (sql) {
stream->write_function(stream, " <registrations>\n");
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, show_reg_callback_xml, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, show_reg_callback_xml, &cb);
switch_safe_free(sql);
stream->write_function(stream, " </registrations>\n");
......@@ -4045,7 +4045,7 @@ SWITCH_STANDARD_API(sofia_count_reg_function)
user, domain, domain);
}
switch_assert(sql);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sql2str_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sql2str_callback, &cb);
switch_safe_free(sql);
if (!zstr(reg_count)) {
stream->write_function(stream, "%s", reg_count);
......@@ -4135,7 +4135,7 @@ SWITCH_STANDARD_API(sofia_username_of_function)
switch_assert(sql);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sql2str_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sql2str_callback, &cb);
switch_safe_free(sql);
if (!zstr(username)) {
stream->write_function(stream, "%s", username);
......@@ -4188,7 +4188,7 @@ static void select_from_profile(sofia_profile_t *profile,
}
switch_assert(sql);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, contact_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, contact_callback, &cb);
switch_safe_free(sql);
}
......
......@@ -625,6 +625,7 @@ struct sofia_profile {
switch_payload_t cng_pt;
uint32_t codec_flags;
switch_mutex_t *ireg_mutex;
switch_mutex_t *dbh_mutex;
switch_mutex_t *gateway_mutex;
sofia_gateway_t *gateways;
//su_home_t *home;
......
......@@ -2499,6 +2499,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Activated db for %s\n", profile->name);
switch_mutex_init(&profile->ireg_mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_mutex_init(&profile->dbh_mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_mutex_init(&profile->gateway_mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_queue_create(&profile->event_queue, SOFIA_QUEUE_SIZE, profile->pool);
......@@ -4872,7 +4873,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 and hostname='%q' and event='call-info' and "
"sub_to_user='%q' and sub_to_host='%q'", mod_sofia_globals.hostname, sip->sip_to->a_url->url_user,
sip->sip_from->a_url->url_host);
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, buf, sizeof(buf));
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s [%s]\n", sql, buf);
......@@ -8241,7 +8242,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 and hostname='%q' and event='call-info' and "
"sub_to_user='%q' and sub_to_host='%q'", mod_sofia_globals.hostname, sip->sip_to->a_url->url_user,
sip->sip_from->a_url->url_host);
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, buf, sizeof(buf));
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s [%s]\n", sql, buf);
......@@ -8378,7 +8379,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
"and call_id is not null",
switch_str_nil(p), user, host, user, host);
if ((str = sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, cid, sizeof(cid)))) {
if ((str = sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, cid, sizeof(cid)))) {
bnh = nua_handle_by_call_id(nua, str);
}
......
......@@ -6445,15 +6445,16 @@ void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql,
{
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
return;
}
if (mutex) {
switch_mutex_lock(mutex);
}
switch_cache_db_persistant_execute_trans_full(dbh, sql, 1,
profile->pre_trans_execute,
profile->post_trans_execute,
......@@ -6473,15 +6474,15 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch
switch_cache_db_handle_t *dbh = NULL;
char *err = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
return;
}
if (mutex) {
switch_mutex_lock(mutex);
}
switch_cache_db_execute_sql(dbh, sql, &err);
if (mutex) {
......@@ -6503,15 +6504,15 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
return ret;
}
if (mutex) {
switch_mutex_lock(mutex);
}
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (mutex) {
......@@ -6537,15 +6538,15 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
char *err = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
return NULL;
}
if (mutex) {
switch_mutex_lock(mutex);
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, &err);
if (mutex) {
......
......@@ -710,7 +710,7 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int
",%d from sip_registrations where call_id='%q' %s", reboot, call_id, sqlextra);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_del_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_del_callback, profile);
switch_safe_free(sql);
sql = switch_mprintf("delete from sip_registrations where call_id='%q' %s", call_id, sqlextra);
......@@ -735,7 +735,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0", reboot);
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_del_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_del_callback, profile);
free(sql);
if (now) {
......@@ -753,7 +753,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' "
"and profile_name='%s' and expires <= %ld", mod_sofia_globals.hostname, profile->name, (long) now);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_sla_dialog_del_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_sla_dialog_del_callback, profile);
free(sql);
sql = switch_mprintf("delete from sip_shared_appearance_dialogs where expires > 0 and hostname='%q' and expires <= %ld",
......@@ -801,7 +801,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
" from sip_registrations where hostname='%s' and "
"profile_name='%s'", mod_sofia_globals.hostname, profile->name);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nat_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_nat_callback, profile);
switch_safe_free(sql);
} else if (sofia_test_pflag(profile, PFLAG_NAT_OPTIONS_PING)) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
......@@ -810,7 +810,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
"or contact like '%%fs_nat=yes%%') and hostname='%s' "
"and profile_name='%s'", mod_sofia_globals.hostname, profile->name);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nat_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_nat_callback, profile);
switch_safe_free(sql);
}
}
......@@ -858,7 +858,7 @@ void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id)
" from sip_registrations where call_id='%q' %s", call_id, sqlextra);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_check_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_check_callback, profile);
switch_safe_free(sql);
......@@ -876,7 +876,7 @@ void sofia_reg_check_sync(sofia_profile_t *profile)
" from sip_registrations where expires > 0");
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_del_callback, profile);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_del_callback, profile);
switch_safe_free(sql);
sql = switch_mprintf("delete from sip_registrations where expires > 0 and hostname='%q'", mod_sofia_globals.hostname);
......@@ -917,7 +917,7 @@ char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const c
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_callback, &cbt);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_find_callback, &cbt);
switch_safe_free(sql);
......@@ -951,7 +951,7 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_multi(sofia_profile_t *p
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_callback, &cbt);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_find_callback, &cbt);
switch_safe_free(sql);
......@@ -980,7 +980,7 @@ switch_console_callback_match_t *sofia_reg_find_reg_url_with_positive_expires_mu
cbt.contact_str = contact_str;
cbt.exptime = exptime;
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_find_reg_with_positive_expires_callback, &cbt);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_find_reg_with_positive_expires_callback, &cbt);
free(sql);
return cbt.list;
......@@ -1031,7 +1031,7 @@ uint32_t sofia_reg_reg_count(sofia_profile_t *profile, const char *user, const c
sql = switch_mprintf("select count(*) from sip_registrations where profile_name='%q' and "
"sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')", profile->name, user, host, host);
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, buf, sizeof(buf));
switch_safe_free(sql);
return atoi(buf);
}
......@@ -1603,7 +1603,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, buf, sizeof(buf));
switch_safe_free(sql);
if (atoi(buf) > 0) {
update_registration = SWITCH_TRUE;
......@@ -2412,10 +2412,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_nonce_callback, &cb);
free(sql);
//if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {
//if (!sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, np, nplen)) {
if (zstr(np)) {
sql = switch_mprintf("delete from sip_authentication where nonce='%q'", nonce);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论