]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
set conditionals to only fire when the mutex can be obtained
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Sep 2010 19:05:48 +0000 (14:05 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Sep 2010 19:05:48 +0000 (14:05 -0500)
src/mod/applications/mod_spandsp/mod_spandsp_fax.c
src/switch_core_sqldb.c

index 1c825ec8dd253a758de56d3fe40d6871de8888dc..51e843778be9393ef333c366239dd1e5e37ddae5 100644 (file)
@@ -120,6 +120,16 @@ static struct {
     int thread_running;
 } t38_state_list;
 
+
+
+static void wake_thread(void)
+{
+       if (switch_mutex_trylock(globals.cond_mutex) == SWITCH_STATUS_SUCCESS) {
+               switch_thread_cond_signal(globals.cond);
+               switch_mutex_unlock(globals.cond_mutex);
+       }
+}
+
 static int add_pvt(pvt_t *pvt)
 {
     int r = 0;
@@ -130,7 +140,7 @@ static int add_pvt(pvt_t *pvt)
         t38_state_list.head = pvt;
         switch_mutex_unlock(t38_state_list.mutex);
         r = 1;
-        switch_thread_cond_broadcast(globals.cond);
+        wake_thread();
     } else {
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error launching thread\n");
     }
@@ -165,7 +175,7 @@ static int del_pvt(pvt_t *del_pvt)
 
     switch_mutex_unlock(t38_state_list.mutex);
 
-    switch_thread_cond_broadcast(globals.cond);
+    wake_thread();
 
     return r;
 }
@@ -1335,7 +1345,7 @@ void mod_spandsp_fax_shutdown(void)
     switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
 
     t38_state_list.thread_running = 0;
-    switch_thread_cond_broadcast(globals.cond);
+    wake_thread();
     switch_thread_join(&tstatus, t38_state_list.thread);
        memset(&globals, 0, sizeof(globals));
 }
index 4a53c8d1fdbbb12f545080391f8c9eb186ebcb10..4c742f342f1405a2a799acb9fb58d81887d47987 100644 (file)
@@ -464,6 +464,14 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
        return status;
 }
 
+static void wake_thread(void)
+{
+       if (switch_mutex_trylock(sql_manager.cond_mutex) == SWITCH_STATUS_SUCCESS) {
+               switch_thread_cond_signal(sql_manager.cond);
+               switch_mutex_unlock(sql_manager.cond_mutex);
+       }
+}
+
 /**
    OMFG you cruel bastards.  Who chooses 64k as a max buffer len for a sql statement, have you ever heard of transactions?
 **/
@@ -1399,7 +1407,7 @@ static void core_event_handler(switch_event_t *event)
                                switch_queue_push(sql_manager.sql_queue[0], sql[i]);
                        }
                        sql[i] = NULL;
-                       switch_thread_cond_broadcast(sql_manager.cond);
+                       wake_thread();
                }
        }
 }
@@ -1673,7 +1681,7 @@ void switch_core_sqldb_stop(void)
                        switch_queue_push(sql_manager.sql_queue[0], NULL);
                        switch_queue_push(sql_manager.sql_queue[1], NULL);
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
-                       switch_thread_cond_broadcast(sql_manager.cond);
+                       wake_thread();
                }
 
                sql_manager.thread_running = -1;