last_progress = time(NULL);
}
ft_index_message(ft_newmsgs[i], 1);
+
+ /* Check to see if we need to quit early */
+ if (time_to_die) {
+ lprintf(CTDL_DEBUG, "Indexer quitting early\n");
+ ft_newhighest = ft_newmsgs[i];
+ break;
+ }
+
}
free(ft_newmsgs);
return;
}
+/*
+ * Main loop for the indexer thread.
+ */
+void *indexer_thread(void *arg) {
+ struct CitContext indexerCC;
+
+ lprintf(CTDL_DEBUG, "indexer_thread() initializing\n");
+
+ memset(&indexerCC, 0, sizeof(struct CitContext));
+ indexerCC.internal_pgm = 1;
+ indexerCC.cs_pid = 0;
+ pthread_setspecific(MyConKey, (void *)&indexerCC );
+
+ cdb_allocate_tsd();
+
+ while (!time_to_die) {
+ do_fulltext_indexing();
+ sleep(1);
+ }
+
+ lprintf(CTDL_DEBUG, "indexer_thread() exiting\n");
+ pthread_exit(NULL);
+}
+
+
/*
* API call to perform searches.
char *serv_fulltext_init(void)
{
- CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER);
CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
return "$Id$";
}
#include "housekeeping.h"
#include "tools.h"
#include "serv_crypto.h"
+#include "serv_fulltext.h"
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
time_t last_purge = 0; /* Last dead session purge */
static int num_threads = 0; /* Current number of threads */
int num_sessions = 0; /* Current number of sessions */
+pthread_t indexer_thread_tid;
int syslog_facility = (-1);
int enable_syslog = 0;
* Initialize a new context and place it in the list. The session number
* used to be the PID (which is why it's called cs_pid), but that was when we
* had one process per session. Now we just assign them sequentially, starting
- * at 1 (don't change it to 0 because masterCC uses 0) and re-using them when
- * sessions terminate.
+ * at 1 (don't change it to 0 because masterCC uses 0).
*/
struct CitContext *CreateNewContext(void) {
struct CitContext *me;
return;
}
- /* Our per-thread stacks need to be bigger than the default size, otherwise
- * the MIME parser crashes on FreeBSD, and the IMAP service crashes on
- * 64-bit Linux.
+ /* Our per-thread stacks need to be bigger than the default size,
+ * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+ * crashes on 64-bit Linux.
*/
- if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) {
- lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n", strerror(ret));
+ if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+ lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+ strerror(ret));
time_to_die = -1;
pthread_attr_destroy(&attr);
return;
}
+/*
+ * Create the indexer thread and begin its operation.
+ */
+void create_indexer_thread(void) {
+ int ret;
+ pthread_attr_t attr;
+
+ if ((ret = pthread_attr_init(&attr))) {
+ lprintf(CTDL_EMERG, "pthread_attr_init: %s\n", strerror(ret));
+ time_to_die = -1;
+ return;
+ }
+
+ /* Our per-thread stacks need to be bigger than the default size,
+ * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+ * crashes on 64-bit Linux.
+ */
+ if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+ lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+ strerror(ret));
+ time_to_die = -1;
+ pthread_attr_destroy(&attr);
+ return;
+ }
+
+ if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0))
+ {
+ lprintf(CTDL_ALERT, "Can't create indexer thread: %s\n",
+ strerror(ret));
+ }
+
+ pthread_attr_destroy(&attr);
+}
+
+
/*
* Purge all sessions which have the 'kill_me' flag set.