X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fserver_main.c;h=592ea7708bbc620f518e10eb21af59406b86642d;hb=a793d2fbf5e0aa9151490b76defd22f6db7ef7ed;hp=363c058cd35b2343850e83e0810f0f0347af97ae;hpb=8c538eeb2d9b024970c350730b4748b870762c5f;p=citadel.git diff --git a/citadel/server_main.c b/citadel/server_main.c index 363c058cd..592ea7708 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -1,7 +1,15 @@ /* * citserver's main() function lives here. + * + * Copyright (c) 1987-2012 by the citadel.org team * - * $Id$ + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "sysdep.h" @@ -38,9 +46,6 @@ #include #include #include -#ifdef HAVE_PTHREAD_H -#include -#endif #ifdef HAVE_SYS_PRCTL_H #include #endif @@ -49,6 +54,7 @@ #include "server.h" #include "serv_extensions.h" #include "sysdep_decls.h" +#include "threads.h" #include "citserver.h" #include "support.h" #include "config.h" @@ -56,7 +62,10 @@ #include "database.h" #include "user_ops.h" #include "housekeeping.h" -#include "citadel_dirs.c" +#include "svn_revision.h" +#include "citadel_dirs.h" + +#include "context.h" #include "modules_init.h" #include "ecrash.h" @@ -72,8 +81,8 @@ const char *CitadelServiceUDS="citadel-UDS"; const char *CitadelServiceTCP="citadel-TCP"; -void go_threading(void); +void go_threading(void); /* * Here's where it all begins. @@ -85,12 +94,12 @@ int main(int argc, char **argv) struct passwd pw, *pwp = NULL; char pwbuf[SIZ]; int drop_root_perms = 1; - size_t size; int relh=0; int home=0; int dbg=0; char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; + int syslog_facility = LOG_DAEMON; #ifdef HAVE_RUN_DIR struct stat filestats; #endif @@ -98,14 +107,10 @@ int main(int argc, char **argv) eCrashParameters params; // eCrashSymbolTable symbol_table; #endif - /* initialise semaphores here. Patch by Matt and davew - * its called here as they are needed by CtdlLogPrintf for thread safety - */ - CtdlInitBase64Table(); - InitialiseSemaphores(); - + /* initialize the master context */ InitializeMasterCC(); + InitializeMasterTSD(); /* parse command-line arguments */ for (a=1; astate > 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) && (CT->state > CTDL_THREAD_STOP_REQ)) - { - /* Ask a worker thread to stop as we no longer need it */ - begin_critical_section(S_THREAD_LIST); - last_worker = CtdlThreadList; - while (last_worker) - { - pthread_mutex_lock(&last_worker->ThreadMutex); - if (last_worker->flags & CTDLTHREAD_WORKER && last_worker->state > CTDL_THREAD_STOPPING) - { - pthread_mutex_unlock(&last_worker->ThreadMutex); - break; - } - pthread_mutex_unlock(&last_worker->ThreadMutex); - last_worker = last_worker->next; - } - end_critical_section(S_THREAD_LIST); - if (last_worker) - { -#ifdef WITH_THREADLOG - CtdlLogPrintf(CTDL_DEBUG, "Thread system, stopping excess worker thread \"%s\" (%ld).\n", - last_worker->name, - last_worker->tid - ); -#endif - CtdlThreadStop(last_worker); - } - } - - /* - * If all our workers are working hard, start some more to help out - * with things - */ - /* FIXME: come up with a better way to dynamically alter the number of threads - * based on the system load - */ -// if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkers() < num_sessions)) - // && (CtdlThreadLoadAvg < 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++) -// for (i=0; i< (10 - (55 - CtdlThreadWorkerAvg) / CtdlThreadWorkerAvg / CtdlThreadGetWorkers()) ; i++) - { -// begin_critical_section(S_THREAD_LIST); - CtdlThreadCreate("Worker Thread", - CTDLTHREAD_BIGSTACK + CTDLTHREAD_WORKER, - worker_thread, - NULL - ); -// end_critical_section(S_THREAD_LIST); - } - } - - CtdlThreadGC(); - - if (CtdlThreadGetCount() <= 1) // Shutting down clean up the garbage collector - { - CtdlThreadGC(); - } - - if (CtdlThreadGetCount()) - CtdlThreadSleep(1); - } - /* - * If the above loop exits we must be shutting down since we obviously have no threads - */ - ctdl_thread_internal_cleanup(); -}