-
-
-
-void go_threading(void)
-{
- int i;
- struct CtdlThreadNode *last_worker;
-
- /* We can't use CT_PUSH() here so we do it the long way
- * So we can still use CT for current thread */
- struct CtdlThreadNode *_this_cit_thread;
-
- /*
- * Initialise the thread system
- */
- ctdl_thread_internal_init();
- _this_cit_thread = CtdlThreadSelf();
- /*
- * Now create a bunch of worker threads.
- */
- CtdlLogPrintf(CTDL_DEBUG, "Starting %d worker threads\n", config.c_min_workers);
- begin_critical_section(S_THREAD_LIST);
- i=0; /* Always start at least 1 worker thread */
- do
- {
- ctdl_internal_create_thread("Worker Thread", CTDLTHREAD_BIGSTACK + CTDLTHREAD_WORKER, worker_thread, NULL);
- } while (++i < config.c_min_workers);
- end_critical_section(S_THREAD_LIST);
-
- /* Second call to module init functions now that threading is up */
- initialise_modules(1);
-
- /*
- * This thread is now used for garbage collection of other threads in the thread list
- */
- CtdlLogPrintf(CTDL_INFO, "Startup thread %d becoming garbage collector,\n", pthread_self());
-
- /* Sleep 10 seconds before first garbage collection */
- CtdlThreadSleep(10);
-
- while (CtdlThreadGetCount())
- {
- if (exit_signal)
- CtdlThreadStopAll();
- begin_critical_section(S_THREAD_LIST);
- ctdl_thread_internal_calc_loadavg();
- end_critical_section(S_THREAD_LIST);
- CtdlThreadSleep(1);
- begin_critical_section(S_THREAD_LIST);
- ctdl_internal_thread_gc();
- end_critical_section(S_THREAD_LIST);
- if (CtdlThreadGetCount() <= 1) // Shutting down clean up the garbage collector
- {
- begin_critical_section(S_THREAD_LIST);
- ctdl_internal_thread_gc();
- end_critical_section(S_THREAD_LIST);
- }
- }
- /*
- * If the above loop exits we must be shutting down since we obviously have no threads
- */
- ctdl_thread_internal_cleanup();
-}