THREADS: config setting min_workers _now_ also is that, plus its also max_spare_workers
[citadel.git] / citadel / threads.c
index ec8fc3feb6f1ff4cce2f2b3bc16da1d09bc8dfb0..bea9665c3c5eba17ec14aa8af7fd6e16f59c431d 100644 (file)
@@ -63,6 +63,7 @@ pthread_mutex_t Critters[MAX_SEMAPHORES];     /* Things needing locking */
 struct thread_tsd masterTSD;
 int server_shutting_down = 0;                  /* set to nonzero during shutdown */
 
+pthread_mutex_t ThreadCountMutex;;
 
 
 void InitializeSemaphores(void)
@@ -191,6 +192,8 @@ void go_threading(void)
                abort();
        }
 
+       pthread_mutex_init(&ThreadCountMutex, NULL);
+
        /* Second call to module init functions now that threading is up */
        initialise_modules(1);
 
@@ -198,13 +201,13 @@ void go_threading(void)
        CtdlThreadCreate(worker_thread);
 
        /* The supervisor thread monitors worker threads and spawns more of them if it finds that
-        * they are all in use.  FIXME make the 256 max threads a configurable value.
+        * they are all in use.
         */
        while (!server_shutting_down) {
-               if ((active_workers == num_workers) && (num_workers < 256)) {
+               if ((active_workers == num_workers) && (num_workers < config.c_max_workers)) {
                        CtdlThreadCreate(worker_thread);
                }
-               usleep(1000);
+               usleep(1000000);
        }
 
        /* When we get to this point we are getting ready to shut down our Citadel server */
@@ -214,7 +217,7 @@ void go_threading(void)
                ShutDownEventQueues();
        }
        while (!EVQShutDown)
-               usleep(1000);
+               usleep(1000000);
 
 
        terminate_all_sessions();               /* close all client sockets */
@@ -226,6 +229,6 @@ void go_threading(void)
                syslog(LOG_DEBUG, "Waiting %d seconds for %d worker threads to exit",
                        countdown, num_workers
                );
-               usleep(1000);
+               usleep(1000000);
        }
 }