A couple of minor speed ups and the beginings of using signals in
[citadel.git] / citadel / server_main.c
index 27942365d7ba7cd90aa37c0e6dcd794de8b6fda8..5c507a578d3a12f5ed8130b334ab2920b66afc02 100644 (file)
@@ -380,15 +380,22 @@ void go_threading(void)
        
        while (CtdlThreadGetCount())
        {
+               if (CT->signal)
+                       exit_signal = CT->signal;
                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);