From 3501087b4d314d7f194f3e705fde989d502a229b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 3 Dec 2010 18:34:07 -0600 Subject: [PATCH] add-on to earlier change to this file --- src/switch_core_sqldb.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index fe12047050..4364ff2844 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -915,9 +915,9 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, char *tmp, *sqlbuf = (char *) malloc(sql_len); char *sql = NULL, *save_sql = NULL; switch_size_t newlen; - int lc = 0; + int lc = 0, wrote = 0, do_sleep = 1; uint32_t sanity = 120; - + switch_assert(sqlbuf); while (!sql_manager.event_db) { @@ -978,6 +978,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, #endif save_sql = sql; sql = NULL; + lc = 0; goto skip; } } @@ -993,10 +994,12 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, } } + lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); + skip: - lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); - + wrote = 0; + if (trans && iterations && (iterations > target || !lc)) { #ifdef DEBUG_SQL switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, @@ -1013,14 +1016,25 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, len = 0; *sqlbuf = '\0'; lc = 0; - switch_yield(400000); + if (do_sleep) { + switch_yield(200000); + } + wrote = 1; } - lc = sql ? 1 : 0 + switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); + lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]); if (!lc) { switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex); + } else if (wrote) { + if (lc > 2000) { + do_sleep = 0; + } else { + do_sleep = 1; + } } + + } switch_mutex_unlock(sql_manager.cond_mutex);