]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/fulltext/serv_fulltext.c
Hunting a bug in scheduled threads that caused a segflt. Got it and
[citadel.git] / citadel / modules / fulltext / serv_fulltext.c
index 4e12ead4ae7c6513378e66a9c90eddc1f116c11e..ef542d8291620039723bc76303fd4b429e76ced5 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "msgbase.h"
 #include "control.h"
 #include "room_ops.h"
-#include "tools.h"
 #include "serv_fulltext.h"
 #include "ft_wordbreaker.h"
 
@@ -233,9 +233,13 @@ void do_fulltext_indexing(void) {
         * Make sure we don't run the indexer too frequently.
         * FIXME move the setting into config
         */
+/*
+ * The thread sleeps for 300 seconds so we don't need this here any more
        if ( (time(NULL) - last_index) < 300L) {
                return;
        }
+*/
 
        /*
         * Check to see whether the fulltext index is up to date; if there
@@ -293,7 +297,7 @@ void do_fulltext_indexing(void) {
                        ft_index_message(ft_newmsgs[i], 1);
 
                        /* Check to see if we need to quit early */
-                       if (time_to_die) {
+                       if (CtdlThreadCheckStop()) {
                                lprintf(CTDL_DEBUG, "Indexer quitting early\n");
                                ft_newhighest = ft_newmsgs[i];
                                break;
@@ -342,15 +346,13 @@ void *indexer_thread(void *arg) {
        indexerCC.cs_pid = 0;
        pthread_setspecific(MyConKey, (void *)&indexerCC );
 
-       cdb_allocate_tsd();
-
-       while (!time_to_die) {
+       while (!CtdlThreadCheckStop()) {
                do_fulltext_indexing();
-               sleep(1);
+               CtdlThreadSleep(300);
        }
 
        lprintf(CTDL_DEBUG, "indexer_thread() exiting\n");
-       pthread_exit(NULL);
+       return NULL;
 }
 
 
@@ -486,12 +488,17 @@ void ft_delete_remove(char *room, long msgnum)
 
 CTDL_MODULE_INIT(fulltext)
 {
-       initialize_ft_cache();
-       CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
-       CtdlRegisterDeleteHook(ft_delete_remove);
-       CtdlRegisterSearchFuncHook(ft_search, "fulltext");
-       CtdlRegisterMaintenanceThread ("indexer", indexer_thread);
-
+       if (!threading)
+       {
+               initialize_ft_cache();
+               CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
+               CtdlRegisterDeleteHook(ft_delete_remove);
+               CtdlRegisterSearchFuncHook(ft_search, "fulltext");
+       }
+       else
+       {
+               CtdlThreadCreate("Indexer", CTDLTHREAD_BIGSTACK, indexer_thread, NULL);
+       }
        /* return our Subversion id for the Log */
        return "$Id$";
 }