]> code.citadel.org Git - citadel.git/blobdiff - citadel/threads.c
Re-Sort Cleanup of event io on shutdown
[citadel.git] / citadel / threads.c
index 59aae25d27f88bd44e3d1749ed75875ce3967421..062d19911870dc59c20660dfe4b6838c82041924 100644 (file)
@@ -183,7 +183,10 @@ void InitializeMasterTSD(void) {
        memset(&masterTSD, 0, sizeof(struct thread_tsd));
 }
 
+extern void ShutDownEventQueues(void);
 
+int EventQShuttingDown = 0;
+int EVQShutDown = 0;
 /*
  * Initialize the thread system
  */
@@ -207,10 +210,18 @@ void go_threading(void)
                if ((active_workers == num_workers) && (num_workers < 256)) {
                        CtdlThreadCreate(worker_thread);
                }
-               sleep(1);
+               usleep(1000);
        }
 
        /* When we get to this point we are getting ready to shut down our Citadel server */
+       if (!EventQShuttingDown)
+       {
+               EventQShuttingDown = 1;
+               ShutDownEventQueues();
+       }
+       while (!EVQShutDown)
+               usleep(1000);
+
 
        terminate_all_sessions();               /* close all client sockets */
        CtdlShutdownServiceHooks();             /* close all listener sockets to prevent new connections */
@@ -221,6 +232,6 @@ void go_threading(void)
                syslog(LOG_DEBUG, "Waiting %d seconds for %d worker threads to exit",
                        countdown, num_workers
                );
-               sleep(1);
+               usleep(1000);
        }
 }