Moved all threading code into threads.c
[citadel.git] / citadel / citserver.c
index cc27e4363c2d923dfd21c6f787a5f3b5ddc09359..e1b2135f7aec14d5cf1f14f82a13e727e8547fd5 100644 (file)
@@ -44,6 +44,7 @@
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
+#include "threads.h"
 #include "citserver.h"
 #include "config.h"
 #include "database.h"
@@ -135,6 +136,10 @@ void master_startup(void) {
        lprintf(CTDL_INFO, "Opening databases\n");
        open_databases();
 
+       ctdl_thread_internal_init_tsd();
+       
+       CtdlThreadAllocTSD();
+       
        if (do_defrag) {
                defrag_databases();
        }
@@ -192,13 +197,13 @@ void master_cleanup(int exitcode) {
        /* Close the AdjRefCount queue file */
        AdjRefCount(-1, 0);
 
+       /* Do system-dependent stuff */
+       sysdep_master_cleanup();
+       
        /* Close databases */
        lprintf(CTDL_INFO, "Closing databases\n");
        close_databases();
 
-       /* Do system-dependent stuff */
-       sysdep_master_cleanup();
-       
 #ifdef DEBUG_MEMORY_LEAKS
        dump_heap();
 #endif
@@ -296,7 +301,11 @@ void cmd_info(void) {
        }
 
        cprintf("%s\n", config.c_default_cal_zone);
-
+       /* Output load averages */
+       cprintf("%f\n", CtdlThreadLoadAvg);
+       cprintf("%f\n", CtdlThreadWorkerAvg);
+       cprintf("%d\n", CtdlThreadGetCount());
+       
        cprintf("000\n");
 }
 
@@ -982,12 +991,16 @@ void citproto_begin_session() {
  */
 void do_command_loop(void) {
        char cmdbuf[SIZ];
-
+       char *old_name = NULL;
+       
+       old_name = CtdlThreadName("do_command_loop");
+       
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
                lprintf(CTDL_ERR, "Client disconnected: ending session.\n");
                CC->kill_me = 1;
+               CtdlThreadName(old_name);
                return;
        }
 
@@ -1016,6 +1029,8 @@ void do_command_loop(void) {
                safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
                time(&CC->lastidle);
        }
+       
+       CtdlThreadName(cmdbuf);
                
        if ((strncasecmp(cmdbuf, "ENT0", 4))
           && (strncasecmp(cmdbuf, "MESG", 4))
@@ -1387,6 +1402,7 @@ void do_command_loop(void) {
 
        /* Run any after-each-command routines registered by modules */
        PerformSessionHooks(EVT_CMD);
+       CtdlThreadName(old_name);
 }