diff -ruN src/trackerd/trackerd.c src/trackerd/trackerd.c --- src/trackerd/trackerd.c 2006-08-04 01:53:48.000000000 +0200 +++ src/trackerd/trackerd.c 2006-08-16 04:20:28.000000000 +0200 @@ -37,23 +37,21 @@ #include #include - #ifdef HAVE_INOTIFY -#include "tracker-inotify.h" +# include "tracker-inotify.h" #else -#ifdef HAVE_FAM -#include "tracker-fam.h" -#endif +# ifdef HAVE_FAM +# include "tracker-fam.h" +# endif #endif #ifndef HAVE_INOTIFY -#ifndef HAVE_FAM -#define POLL_ONLY -#include "tracker-db.h" +# ifndef HAVE_FAM +# define POLL_ONLY +# endif #endif -#endif - +#include "tracker-db.h" #include "tracker-metadata.h" #include "tracker-dbus-methods.h" #include "tracker-dbus-metadata.h" @@ -92,7 +90,7 @@ * asynchronous queue where potentially multiple threads are waiting to process them. */ -#define FILE_POLL_PERIOD 30 * 60 * 1000 +#define FILE_POLL_PERIOD (30 * 60 * 1000) char *type_array[] = {"index", "string", "numeric", "date", NULL}; @@ -124,7 +122,7 @@ static GAsyncQueue *file_process_queue; #else GAsyncQueue *file_process_queue; -#endif +#endif /* POLL_ONLY */ GAsyncQueue *user_request_queue; @@ -147,14 +145,11 @@ static gboolean is_running = FALSE; -static GMutex *process_thread_mutex = NULL; -static GMutex *metadata_thread_mutex = NULL; static GMutex *user_thread1_mutex = NULL; -static GMutex *user_thread2_mutex = NULL; static GMutex *poll_thread_mutex = NULL; - - +static GThread *file_metadata_thread = NULL; +static GThread *file_process_thread = NULL; static GThread *file_poll_thread = NULL; static void schedule_file_check (const char * uri, DBConnection *db_con); @@ -170,7 +165,7 @@ #ifdef POLL_ONLY -#define MAX_FILE_WATCHES -1 +#define MAX_FILE_WATCHES (-1) gboolean tracker_start_watching (void){return TRUE;} void tracker_end_watching (void){return;} @@ -180,14 +175,12 @@ gboolean tracker_is_directory_watched (const char * dir, DBConnection *db_con) {return FALSE;} int tracker_count_watch_dirs (void) {return 0;} -#endif +#endif /* POLL_ONLY */ static void do_cleanup () { - - tracker_print_object_allocations (); /* stop threads from further processing of events if possible */ @@ -195,18 +188,26 @@ /* acquire thread mutexes - we wait until all threads have been stopped and DB connections closed */ - g_mutex_lock (process_thread_mutex); - g_mutex_lock (metadata_thread_mutex); + if (file_process_thread) + g_thread_join (file_process_thread); + if (file_metadata_thread) + g_thread_join (file_metadata_thread); + g_mutex_lock (user_thread1_mutex); - g_mutex_lock (user_thread2_mutex); tracker_end_watching (); + tracker_dbus_shutdown (main_connection); + g_main_loop_quit (loop); + /* we are supposed to be in the main thread now */ + mysql_close (main_thread_db_con->db); + + mysql_thread_end (); + /* This must be called after all other mysql functions */ mysql_server_end (); - } static int @@ -469,7 +470,7 @@ tracker_log ("Received fatal signal %s so now aborting.",g_strsignal (signo)); } do_cleanup (); - exit (1); + exit (EXIT_FAILURE); break; case SIGTERM: @@ -478,7 +479,7 @@ tracker_log ("Received termination signal %s so now exiting", g_strsignal (signo)); } do_cleanup(); - exit (0); + exit (EXIT_SUCCESS); break; @@ -797,16 +798,11 @@ /* set thread safe DB connection */ mysql_thread_init (); - /* set mutex so we know if the thread is still processing */ - g_mutex_lock (metadata_thread_mutex); - db_con.db = tracker_db_connect (); tracker_db_prepare_queries (&db_con); while (is_running) { - - g_mutex_unlock (metadata_thread_mutex); info = g_async_queue_try_pop (file_metadata_queue); @@ -840,7 +836,6 @@ tracker_exec_proc (db_con.db, "RemovePendingMetadataFiles", 0); - /* relock mutex if more files still available */ res = tracker_exec_proc (db_con.db, "CountPendingMetadataFiles", 0); if (res) { @@ -861,8 +856,6 @@ continue; } - - g_mutex_lock (metadata_thread_mutex); /* info struct may have been deleted in transit here so check if still valid and intact */ g_return_if_fail ( tracker_file_info_is_valid (info)); @@ -939,9 +932,6 @@ mysql_close (db_con.db); mysql_thread_end (); - - /* unlock mutex so we know thread has exited */ - g_mutex_unlock (metadata_thread_mutex); } @@ -1021,16 +1011,11 @@ /* set thread safe DB connection */ mysql_thread_init (); - /* used to indicate if no db action is occuring in thread */ - g_mutex_lock (process_thread_mutex); - db_con.db = tracker_db_connect (); while (is_running) { - g_mutex_unlock (process_thread_mutex); - info = g_async_queue_try_pop (file_process_queue); /* check pending table if we haven't got anything */ @@ -1067,8 +1052,6 @@ tracker_exec_proc (db_con.db, "RemovePendingFiles", 0); - - /* relock mutex if more files still available */ res = tracker_exec_proc (db_con.db, "ExistsPendingFiles", 0); if (res) { @@ -1091,8 +1074,6 @@ } - g_mutex_lock (process_thread_mutex); - /* info struct may have been deleted in transit here so check if still valid and intact */ if (!tracker_file_info_is_valid (info)) { continue; @@ -1245,9 +1226,6 @@ mysql_close (db_con.db); mysql_thread_end (); - - /* unlock mutex so we know thread has exited */ - g_mutex_unlock (process_thread_mutex); } static void @@ -1561,7 +1539,7 @@ sigset_t empty_mask; char *prefix, *lock_file, *str, *lock_str, *tracker_data_dir; - GThread *file_metadata_thread, *file_process_thread, *user_request_thread1; + GThread *user_request_thread1; gboolean need_setup = FALSE; DBConnection db_con; @@ -1682,7 +1660,7 @@ sigemptyset (&empty_mask); act.sa_handler = signal_handler; act.sa_mask = empty_mask; - act.sa_flags = 0; + act.sa_flags = SA_NODEFER; sigaction (SIGTERM, &act, NULL); sigaction (SIGILL, &act, NULL); sigaction (SIGBUS, &act, NULL); @@ -1819,18 +1797,9 @@ is_running = TRUE; /* thread mutexes - so we know when a thread is not busy */ - g_assert (process_thread_mutex == NULL); - process_thread_mutex = g_mutex_new (); - - g_assert (metadata_thread_mutex == NULL); - metadata_thread_mutex = g_mutex_new (); - g_assert (user_thread1_mutex == NULL); user_thread1_mutex = g_mutex_new (); - g_assert (user_thread2_mutex == NULL); - user_thread2_mutex = g_mutex_new (); - g_assert (poll_thread_mutex == NULL); poll_thread_mutex = g_mutex_new (); @@ -1858,19 +1827,17 @@ /* execute events and user requests to be processed and indexed in their own threads */ - file_process_thread = g_thread_create ((GThreadFunc) process_files_thread, NULL, FALSE, NULL); - file_metadata_thread = g_thread_create ((GThreadFunc) extract_metadata_thread, NULL, FALSE, NULL); + file_process_thread = g_thread_create ((GThreadFunc) process_files_thread, NULL, TRUE, NULL); + file_metadata_thread = g_thread_create ((GThreadFunc) extract_metadata_thread, NULL, TRUE, NULL); user_request_thread1 = g_thread_create ((GThreadFunc) process_user_request_queue_thread, user_thread1_mutex, FALSE, NULL); g_main_loop_run (loop); - mysql_close (db_con.db); - - mysql_thread_end (); - - tracker_dbus_shutdown (main_connection); - - do_cleanup (); + /* + * This position will never be reached since we are in the main thread + * and we use signal trapping in it... + */ + g_assert (FALSE); - return 0; + return EXIT_SUCCESS; /* just to be C-friendly */ }