]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add-on to earlier change to this file
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 4 Dec 2010 00:34:07 +0000 (18:34 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 4 Dec 2010 02:22:14 +0000 (20:22 -0600)
src/switch_core_sqldb.c

index fe12047050a2860e6d39a2547664293cda582587..4364ff2844cce0319cfc041b6540369b5bb7fa6d 100644 (file)
@@ -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,
                        }
                }
 
-       skip:
-               
                lc = switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]);
+
+       skip:
                
+               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);