* remove the need for the calls to eCrashRegisterThread and friends
*/
+static int next_tid = 3; /* offset LWPID to PID */
static int num_threads = 0; /* Current number of threads */
static int num_workers = 0; /* Current number of worker threads */
long statcount = 0; /* are we doing a stats check? */
GC_thread->state = CTDL_THREAD_STOP_REQ;
while(this_thread)
{
-#ifdef THREADS_USESIGNALS
if (!citthread_equal(this_thread->tid, GC_thread->tid))
citthread_kill(this_thread->tid, SIGHUP);
-#endif
+
ctdl_thread_internal_change_state (this_thread, CTDL_THREAD_STOP_REQ);
citthread_cond_signal(&this_thread->ThreadCond);
citthread_cond_signal(&this_thread->SleepCond);
double CtdlThreadGetLoadAvg(void)
{
- double load_avg[3] ;
+ double load_avg[3] = {0.0, 0.0, 0.0};
- int ret;
+ int ret = 0;
int smp_num_cpus;
/* Borrowed this straight from procps */
smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */
+#ifdef HAVE_GETLOADAVG
ret = getloadavg(load_avg, 3);
+#endif
if (ret < 0)
return 0;
return load_avg[0] / smp_num_cpus;
state = CT->state;
-#ifdef THREADS_USESIGNALS
if (CT->signal)
{
CtdlLogPrintf(CTDL_DEBUG, "Thread \"%s\" caught signal %d.\n", CT->name, CT->signal);
+ if (CT->signal == SIGHUP)
+ CT->state = CTDL_THREAD_STOP_REQ;
CT->signal = 0;
}
-#endif
if(state == CTDL_THREAD_STOP_REQ)
{
CT->state = CTDL_THREAD_STOPPING;
return;
if (!(this_thread->thread_func))
return; // Don't stop garbage collector
-#ifdef THREADS_USESIGNALS
+
if (!citthread_equal(this_thread->tid, GC_thread->tid))
citthread_kill(this_thread->tid, SIGHUP);
-#endif
+
ctdl_thread_internal_change_state (this_thread, CTDL_THREAD_STOP_REQ);
citthread_cond_signal(&this_thread->ThreadCond);
citthread_cond_signal(&this_thread->SleepCond);
* In here we were called by the current thread because it is exiting
* NB. WE ARE THE CURRENT THREAD
*/
- CtdlLogPrintf(CTDL_NOTICE, "Thread \"%s\" (0x%08lx) exited.\n", CT->name, CT->tid);
+ if (CT)
+ {
+ const char *name = CT->name;
+ const pid_t tid = CT->tid;
+
+ CtdlLogPrintf(CTDL_NOTICE, "Thread \"%s\" (0x%08lx) exited.\n", name, tid);
+ }
+ else
+ {
+ CtdlLogPrintf(CTDL_NOTICE, "some ((unknown ? ? ?) Thread exited.\n");
+ }
#ifdef HAVE_BACKTRACE
- eCrash_UnregisterThread();
+/// eCrash_UnregisterThread();
#endif
citthread_mutex_lock(&CT->ThreadMutex);
CtdlThreadNode *this_thread, *that_thread;
int workers = 0, sys_workers;
int ret=0;
-
+
begin_critical_section(S_THREAD_LIST);
/* Handle exiting of garbage collector thread */
// Register for tracing
#ifdef HAVE_BACKTRACE
- eCrash_RegisterThread(this_thread->name, 0);
+/// eCrash_RegisterThread(this_thread->name, 0);
#endif
// Tell the world we are here
free(this_thread);
return NULL;
}
-
+ this_thread->reltid = next_tid;
+ next_tid++;
num_threads++; // Increase the count of threads in the system.
if(this_thread->flags & CTDLTHREAD_WORKER)
num_workers++;
ctdl_thread_internal_init();
/* Second call to module init functions now that threading is up */
- if (!statcount)
+ if (!statcount) {
initialise_modules(1);
+ CtdlThreadCreate("select_on_master", CTDLTHREAD_BIGSTACK, select_on_master, NULL);
+ }
else {
CtdlLogPrintf(CTDL_EMERG, "Running connection simulation stats\n");
gettimeofday(&start, NULL);