]> code.citadel.org Git - citadel.git/blobdiff - citadel/server_main.c
Prevent an ocassional segflt on exit.
[citadel.git] / citadel / server_main.c
index 20bc5dddf0629e0b2912e60a5a7fe2fa0b90302e..c46c0857a2375fa55bd52064429cfe09f8ea4573 100644 (file)
@@ -383,12 +383,15 @@ 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);
+               }
+               
                /* 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);
@@ -426,7 +429,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++)