Index: src/switch_core.c =================================================================== --- src/switch_core.c (revision 2718) +++ src/switch_core.c (working copy) @@ -141,6 +141,9 @@ /* The main runtime obj we keep this hidden for ourselves */ static struct switch_core_runtime runtime; +static switch_mutex_t *EVENT_SQL_MUTEX = NULL; +static switch_thread_cond_t *EVENT_SQL_CONDITIONAL = NULL; + static void db_pick_path(char *dbname, char *buf, switch_size_t size) { @@ -3208,12 +3211,17 @@ uint8_t trans = 0; switch_time_t last_commit = switch_time_now(); uint32_t freq = 1000, target = 1000, diff = 0; - + + assert(EVENT_SQL_MUTEX != NULL); + assert(EVENT_SQL_CONDITIONAL != NULL); + if (!runtime.event_db) { runtime.event_db = switch_core_db_handle(); } switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool); + switch_mutex_lock(EVENT_SQL_MUTEX); + for(;;) { uint32_t work = 0; @@ -3259,7 +3267,8 @@ diff = 0; } if (!work) { - switch_yield(1000); + switch_thread_cond_wait(EVENT_SQL_CONDITIONAL, EVENT_SQL_MUTEX); + //switch_yield(1000); } } return NULL; @@ -3273,6 +3282,9 @@ assert(runtime.memory_pool != NULL); + switch_mutex_init(&EVENT_SQL_MUTEX, SWITCH_MUTEX_NESTED, runtime.memory_pool); + switch_thread_cond_create(&EVENT_SQL_CONDITIONAL, runtime.memory_pool); + switch_threadattr_create(&thd_attr, runtime.memory_pool); switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); @@ -3285,6 +3297,10 @@ { char *sql = NULL; + if(switch_mutex_trylock(EVENT_SQL_MUTEX) == SWITCH_STATUS_SUCCESS) { + switch_thread_cond_signal(EVENT_SQL_CONDITIONAL); + switch_mutex_unlock(EVENT_SQL_MUTEX); + } switch (event->event_id) { case SWITCH_EVENT_CHANNEL_DESTROY: sql = switch_core_db_mprintf("delete from channels where uuid='%s'", switch_event_get_header(event, "unique-id"));