]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix race
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 17:25:48 +0000 (17:25 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 Mar 2007 17:25:48 +0000 (17:25 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4810 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_core.c
src/switch_core_sqldb.c
src/switch_event.c

index ceb502bfb5c0a4d01f0d620c89fc74c9f7817b31..62e4de2dd7293ebc978ee75759c7e5bd5372fedf 100644 (file)
@@ -482,6 +482,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console, const char **err
        assert(runtime.memory_pool != NULL);
        switch_log_init(runtime.memory_pool);
        switch_event_init(runtime.memory_pool);
+
        switch_core_sqldb_start(runtime.memory_pool);
        switch_rtp_init(runtime.memory_pool);
        runtime.running = 1;
index 1313048a2a397e3bcba751466658fd99b0a44177..6ceb193eacd31cb2634205f033b7b32652612dfe 100644 (file)
@@ -39,6 +39,7 @@ static struct {
        switch_core_db_t *event_db;
        switch_queue_t *sql_queue;
        switch_memory_pool_t *memory_pool;
+       int thread_running;
 } runtime;
 
 static switch_status_t switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries)
@@ -159,9 +160,8 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t * thread,
        if (!runtime.event_db) {
                runtime.event_db = switch_core_db_handle();
        }
-       switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool);
-
 
+       runtime.thread_running = 1;
 
        for (;;) {
                if (switch_queue_trypop(runtime.sql_queue, &pop) == SWITCH_STATUS_SUCCESS) {
@@ -398,11 +398,15 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool)
                }
        }
 
+       switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, 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);
        switch_thread_create(&thread, thd_attr, switch_core_sql_thread, NULL, runtime.memory_pool);
-
+       while (!runtime.thread_running) {
+               switch_yield(10000);
+       }
 }
 
 void switch_core_sqldb_stop(void)
index eef532181f8bedf606a012ece5bd8662c74e673c..a3a02770e8970d02d2031994bd0bbba164759a6b 100644 (file)
@@ -398,13 +398,14 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
        switch_threadattr_detach_set(thd_attr, 1);
 
        assert(pool != NULL);
-       RUNTIME_POOL = pool;
-
+       THRUNTIME_POOL = RUNTIME_POOL = pool;
 
+       /*
        if (switch_core_new_memory_pool(&THRUNTIME_POOL) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
                return SWITCH_STATUS_MEMERR;
        }
+       */
        /*
           if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
           switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not allocate memory pool\n");