struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
void CtdlThreadSleep(int secs);
void CtdlThreadStop(struct CtdlThreadNode *thread);
-int CtdlThreadCheckStop(void);
+int CtdlThreadCheckStop(struct CtdlThreadNode *thread);
void CtdlThreadCancel(struct CtdlThreadNode *thread);
char *CtdlThreadName(struct CtdlThreadNode *thread, char *name);
struct CtdlThreadNode *CtdlThreadSelf(void);
int CtdlThreadGetCount(void);
void CtdlThreadGC(void);
void CtdlThreadStopAll(void);
+/* Macros to speed up getting outr thread */
+#define CT _this_cit_thread
+#define CT_PUSH() \
+ struct CtdlThreadNode *_this_cit_thread;\
+ _this_cit_thread = CtdlThreadSelf()
+
+
#ifdef WITH_THREADLOG
#define CtdlThreadPushName(NAME) \
char *_push_name; \
time_t run_time = 0L;
time_t end_time = 0L;
+ CT_PUSH();
+
/*
* Don't do this if the site doesn't have it enabled.
*/
ft_index_message(ft_newmsgs[i], 1);
/* Check to see if we need to quit early */
- if (CtdlThreadCheckStop()) {
+ if (CtdlThreadCheckStop(CT)) {
lprintf(CTDL_DEBUG, "Indexer quitting early\n");
ft_newhighest = ft_newmsgs[i];
break;
void *indexer_thread(void *arg) {
struct CitContext indexerCC;
+ CT_PUSH();
+
lprintf(CTDL_DEBUG, "indexer_thread() initializing\n");
memset(&indexerCC, 0, sizeof(struct CitContext));
cdb_allocate_tsd();
- while (!CtdlThreadCheckStop()) {
+ while (!CtdlThreadCheckStop(CT)) {
do_fulltext_indexing();
CtdlThreadSleep(300);
}
return num_threads;
}
+int CtdlThreadGetWorkers(void)
+{
+ return num_workers;
+}
+
/*
* A function to find the thread structure for this thread
*/
this_thread = thread;
if (!this_thread)
{
- CtdlLogPrintf(CTDL_WARNING, "Thread system WARNING. Attempt to CtdlThreadRename() a non thread.\n");
+ CtdlLogPrintf(CTDL_WARNING, "Thread system WARNING. Attempt to CtdlThreadRename() a non thread. %s\n", name);
return NULL;
}
begin_critical_section(S_THREAD_LIST);
/*
* A function for a thread to check if it has been asked to stop
*/
-int CtdlThreadCheckStop(void)
+int CtdlThreadCheckStop(struct CtdlThreadNode *this_thread)
{
- struct CtdlThreadNode *this_thread;
-
- this_thread = CtdlThreadSelf();
if (!this_thread)
{
CtdlLogPrintf(CTDL_EMERG, "Thread system PANIC, CtdlThreadCheckStop() called by a non thread.\n");
CtdlThreadStopAll();
return -1;
}
+ pthread_mutex_lock(&this_thread->ThreadMutex);
if(this_thread->state == CTDL_THREAD_STOP_REQ)
{
this_thread->state = CTDL_THREAD_STOPPING;
+ pthread_mutex_unlock(&this_thread->ThreadMutex);
return -1;
}
else if(this_thread->state < CTDL_THREAD_STOP_REQ)
+ {
+ pthread_mutex_unlock(&this_thread->ThreadMutex);
return -1;
-
+ }
+ pthread_mutex_unlock(&this_thread->ThreadMutex);
return 0;
}
struct timeval tv;
int force_purge = 0;
int m;
-
+
+ CT_PUSH();
+
cdb_allocate_tsd();
- while (!CtdlThreadCheckStop()) {
+ while (!CtdlThreadCheckStop(CT)) {
/* make doubly sure we're not holding any stale db handles
* which might cause a deadlock.
}
}
- if (!CtdlThreadCheckStop()) {
+ if (!CtdlThreadCheckStop(CT)) {
tv.tv_sec = 1; /* wake up every second if no input */
tv.tv_usec = 0;
retval = CtdlThreadSelect(highest + 1, &readfds, NULL, NULL, &tv);
// retval = select(highest + 1, &readfds, NULL, NULL, &tv);
}
- if (CtdlThreadCheckStop()) return(NULL);
+ if (CtdlThreadCheckStop(CT)) return(NULL);
/* Now figure out who made this select() unblock.
* First, check for an error or exit condition.
if (errno != EINTR) {
CtdlLogPrintf(CTDL_EMERG, "Exiting (%s)\n", strerror(errno));
CtdlThreadStopAll();
- } else if (!CtdlThreadCheckStop()) {
+ } else if (!CtdlThreadCheckStop(CT)) {
CtdlLogPrintf(CTDL_DEBUG, "Un handled select failure.\n");
goto do_select;
}