]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add dedicated mutex for select based sql stuff
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 25 Feb 2013 21:42:21 +0000 (15:42 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 25 Feb 2013 21:42:26 +0000 (15:42 -0600)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index b5e4190fef1e29a484aec591fd8d6236f2c39bef..3a5162c398de5892e317843394ea5c945b569797 100644 (file)
@@ -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);
 }
 
index 6617acd35b6e6121fb933175dfa1b257e6f00a88..ee4776de51e1a828aff5e1708fed9fb4dfffc6cb 100644 (file)
@@ -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;
index 743a0371ecb0fba18d755ebd3479f02a773e1659..69d6fd72692ec845f1bad1b31542b3ec18b9a73c 100644 (file)
@@ -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);
                        }
 
index 8b8f388ba9cb82d2280b57d928ed403635435515..15f6d529f2e42b37b8c00535f8009abab699bbf0 100644 (file)
@@ -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) {
index 4ad83e61571c252833a982e14db582b4c7921fa6..6ac946adf43c999bdf9fca65081f52e147115edc 100644 (file)
@@ -423,7 +423,7 @@ void sofia_presence_cancel(void)
                                                                                 "event='presence' and hostname='%q' and profile_name='%q'",
                                                                                 mod_sofia_globals.hostname, profile->name);
                                        
-                                       r = sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
+                                       r = sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_sub_callback, &helper);
                                        switch_safe_free(sql);
 
                                        if (r != SWITCH_TRUE) {
@@ -525,7 +525,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
                                for (m = matches->head; m; m = m->next) {
                                        if ((profile = sofia_glue_find_profile(m->val))) {
 
-                                               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 (!zstr(buf)) {
                                                        break;
                                                }
@@ -591,7 +591,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
 
 
        if (sql) {
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_mwi_callback, &h);
                free(sql);
                sql = NULL;
 
@@ -609,7 +609,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
 
        if (sql) {
                switch_assert(sql != NULL);
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_mwi_callback2, &h);
                free(sql);
                sql = NULL;
        }
@@ -688,7 +688,7 @@ static void do_normal_probe(switch_event_t *event)
                                                         mod_sofia_globals.hostname, profile->name, probe_euser, probe_host, probe_euser, probe_host);
                
                
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_dialog_callback, &dh);
 
                h.profile = profile;
 
@@ -742,7 +742,7 @@ static void do_normal_probe(switch_event_t *event)
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
                }
 
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_resub_callback, &h);
                switch_safe_free(sql);          
 
                if (!h.rowcount) {
@@ -769,7 +769,7 @@ static void do_normal_probe(switch_event_t *event)
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
                        }
 
-                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
+                       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_resub_callback, &h);
                        switch_safe_free(sql);
                
                        if (mod_sofia_globals.debug_presence > 0) {
@@ -864,7 +864,7 @@ static void do_dialog_probe(switch_event_t *event)
                h4235->pool = pool;
                h4235->profile = profile;
                switch_core_hash_init(&h4235->hash, h4235->pool);
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_dialog_probe_callback, h4235);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_dialog_probe_callback, h4235);
                switch_safe_free(sql);
                if (mod_sofia_globals.debug_presence > 0) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END DIALOG_PROBE_SQL\n\n", profile->name);
@@ -892,7 +892,7 @@ static void do_dialog_probe(switch_event_t *event)
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s DUMP DIALOG_PROBE subscription sql:\n%s\n", profile->name, sql);
                }
 
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_dialog_probe_notify_callback, h4235);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_dialog_probe_notify_callback, h4235);
                switch_safe_free(sql);
 
                sofia_glue_release_profile(profile);
@@ -985,7 +985,7 @@ static void send_conference_data(sofia_profile_t *profile, switch_event_t *event
                                                         from_user, from_host, event_str);
        }
 
-       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
+       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_send_sql, &cb);
        switch_safe_free(sql);
 
        if (switch_true(final)) {
@@ -1189,7 +1189,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                        memset(&helper, 0, sizeof(helper));
                                        helper.profile = profile;
                                        helper.event = NULL;
-                                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
+                                       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_sub_callback, &helper);
                                        switch_safe_free(sql);
                                        sofia_glue_release_profile(profile);
                                }
@@ -1332,7 +1332,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK SQL: %s@%s [%s]\nhits: %d\n", euser, host, sql, dh.hits);
                                }
 
-                               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
+                               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_dialog_callback, &dh);
                                
 
                                switch_safe_free(sql);
@@ -1479,7 +1479,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                        free(buf);
                                }
 
-                               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
+                               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_sub_callback, &helper);
                                switch_safe_free(sql);
                        
                                if (mod_sofia_globals.debug_presence > 0) {
@@ -3368,7 +3368,7 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t
                                                                 
                                                                 "and event='line-seize'", call_id);
                        
-                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
+                       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_send_sql, &cb);
                        if (mod_sofia_globals.debug_sla > 1) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
                        }
@@ -3399,7 +3399,7 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t
                                                                 mod_sofia_globals.hostname, profile->name, to_user, to_host
                                                                 );
                        
-                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
+                       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_send_sql, &cb);
 
                        if (mod_sofia_globals.debug_sla > 1) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
@@ -3437,7 +3437,7 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t
        if (mod_sofia_globals.debug_sla > 1) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
        }
-       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_gather_state_callback, sh);
+       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, broadsoft_sla_gather_state_callback, sh);
        switch_safe_free(sql);
 
 
@@ -3479,7 +3479,7 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t
        }
 
        sh->profile = profile;
-       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_notify_callback, sh);
+       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, broadsoft_sla_notify_callback, sh);
        switch_safe_free(sql);
        total = sh->total;
        sh = NULL;
@@ -3644,7 +3644,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
        if ((sub_state != nua_substate_terminated)) {
                sql = switch_mprintf("select count(*) from sip_subscriptions where call_id='%q' and hostname='%q' and profile_name='%q'", 
                                                         call_id, mod_sofia_globals.hostname, profile->name);
-               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_presence > 0 || mod_sofia_globals.debug_sla > 0) {
@@ -3951,7 +3951,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                        }
 
 
-                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
+                       sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_sub_reg_callback, profile);
 
                        switch_safe_free(sql);
                }
@@ -4180,7 +4180,7 @@ uint32_t sofia_presence_contact_count(sofia_profile_t *profile, const char *cont
        sql = switch_mprintf("select count(*) from sip_subscriptions where hostname='%q' and profile_name='%q' and contact='%q'", 
                                                 mod_sofia_globals.hostname, profile->name, contact_str);
        
-       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);                               
 }
@@ -4307,7 +4307,7 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n
                                                                         mod_sofia_globals.hostname, profile->name,
                                                                         from_user, from_host, event_type, contact_str);
                                                                         
-                               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
+                               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_send_sql, &cb);
                                switch_safe_free(sql);
                        }
 
@@ -4629,7 +4629,7 @@ void sofia_presence_check_subscriptions(sofia_profile_t *profile, time_t now)
                                                         " from sip_subscriptions where ((expires > 0 and expires <= %ld)) and profile_name='%q' and hostname='%q'",
                                                         (long) now, profile->name, mod_sofia_globals.hostname);
 
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
+               sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_send_sql, &cb);
                switch_safe_free(sql);
 
                if (cb.ttl) {
index 4f0892491968b70ca20af01801225ebd414f08d7..952c9b577435302d1e453896650e14693599baac 100644 (file)
@@ -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);