]> code.citadel.org Git - citadel.git/blobdiff - citadel/server_main.c
Added the functions to allow scheduling of a thread to start at some
[citadel.git] / citadel / server_main.c
index 343d0ae13b2daffce1cf72aad7fffe9f32d7c4bd..363c058cd35b2343850e83e0810f0f0347af97ae 100644 (file)
@@ -347,15 +347,10 @@ void go_threading(void)
        int i;
        struct CtdlThreadNode *last_worker;
        
-       /* We can't use CT_PUSH() here so we do it the long way 
-        * So we can still use CT for current thread */
-       struct CtdlThreadNode *_this_cit_thread;
-       
        /*
         * Initialise the thread system
         */
        ctdl_thread_internal_init();
-       _this_cit_thread = CtdlThreadSelf();
        /*
         * Now create a bunch of worker threads.
         */
@@ -388,12 +383,17 @@ void go_threading(void)
                if (exit_signal)
                        CtdlThreadStopAll();
                check_sched_shutdown();
-               begin_critical_section(S_THREAD_LIST);
-               ctdl_thread_internal_calc_loadavg();
-               end_critical_section(S_THREAD_LIST);
-       
+               if (CT->state > CTDL_THREAD_STOP_REQ)
+               {
+                       begin_critical_section(S_THREAD_LIST);
+                       ctdl_thread_internal_calc_loadavg();
+                       end_critical_section(S_THREAD_LIST);
+                       
+                       ctdl_thread_internal_check_scheduled(); /* start scheduled threads */
+               }
+               
                /* Reduce the size of the worker thread pool if necessary. */
-               if ((CtdlThreadGetWorkers() > config.c_min_workers) && (CtdlThreadWorkerAvg < 20))
+               if ((CtdlThreadGetWorkers() > config.c_min_workers) && (CtdlThreadWorkerAvg < 20) && (CT->state > CTDL_THREAD_STOP_REQ))
                {
                        /* Ask a worker thread to stop as we no longer need it */
                        begin_critical_section(S_THREAD_LIST);
@@ -431,7 +431,7 @@ void go_threading(void)
                 */
 //             if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkers() < num_sessions))
                // && (CtdlThreadLoadAvg < 90) )
-               if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkerAvg() > 60) && (CtdlThreadGetLoadAvg() < 90) )
+               if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkerAvg() > 60) && (CtdlThreadGetLoadAvg() < 90) && (CT->state > CTDL_THREAD_STOP_REQ))
                {
                        for (i=0; i<5 ; i++)
 //                     for (i=0; i< (num_sessions - CtdlThreadGetWorkers()) ; i++)