[tracker/tracker-1.10] libtracker-extract: Ditch ThreadAwareness module configuration toggle



commit a381df112eb9b447b726544215599a5862fe8639
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Dec 6 17:01:09 2016 +0100

    libtracker-extract: Ditch ThreadAwareness module configuration toggle
    
    It's basically unused, just use a private thread per-module so they're
    easier to isolate.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764786

 src/libtracker-extract/tracker-data.h           |    3 +-
 src/libtracker-extract/tracker-module-manager.c |   19 +----
 src/libtracker-extract/tracker-module-manager.h |   33 +--------
 src/tracker-extract/tracker-extract-text.c      |    8 --
 src/tracker-extract/tracker-extract.c           |   89 +++++++----------------
 5 files changed, 32 insertions(+), 120 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-data.h b/src/libtracker-extract/tracker-data.h
index 05b00db..d0609d4 100644
--- a/src/libtracker-extract/tracker-data.h
+++ b/src/libtracker-extract/tracker-data.h
@@ -45,8 +45,7 @@ G_BEGIN_DECLS
  * application, look at the TrackerDecorator class from libtracker-miner.
  */
 
-gboolean tracker_extract_module_init     (TrackerModuleThreadAwareness  *thread_awareness_ret,
-                                          GError                       **error);
+gboolean tracker_extract_module_init     (GError **error);
 gboolean tracker_extract_module_shutdown (void);
 
 /**
diff --git a/src/libtracker-extract/tracker-module-manager.c b/src/libtracker-extract/tracker-module-manager.c
index 175c83e..15f2964 100644
--- a/src/libtracker-extract/tracker-module-manager.c
+++ b/src/libtracker-extract/tracker-module-manager.c
@@ -35,7 +35,6 @@ typedef struct {
 
 typedef struct {
        GModule *module;
-       TrackerModuleThreadAwareness thread_awareness;
        TrackerExtractMetadataFunc extract_func;
        TrackerExtractInitFunc init_func;
        TrackerExtractShutdownFunc shutdown_func;
@@ -45,8 +44,7 @@ typedef struct {
 static gboolean dummy_extract_func (TrackerExtractInfo *info);
 
 static ModuleInfo dummy_module = {
-       NULL, TRACKER_MODULE_MAIN_THREAD,
-       dummy_extract_func, NULL, NULL, TRUE
+       NULL, dummy_extract_func, NULL, NULL, TRUE
 };
 
 static GHashTable *modules = NULL;
@@ -375,7 +373,7 @@ load_module (RuleInfo *info,
                if (module_info->init_func) {
                        GError *error = NULL;
 
-                       if (!(module_info->init_func) (&module_info->thread_awareness, &error)) {
+                       if (!(module_info->init_func) (&error)) {
                                g_critical ("Could not initialize module %s: %s",
                                            g_module_name (module_info->module),
                                            (error) ? error->message : "No error given");
@@ -386,8 +384,6 @@ load_module (RuleInfo *info,
 
                                return NULL;
                        }
-               } else {
-                       module_info->thread_awareness = TRACKER_MODULE_MAIN_THREAD;
                }
 
                module_info->initialized = TRUE;
@@ -530,12 +526,10 @@ tracker_extract_module_manager_get_mimetype_handlers (const gchar *mimetype)
  * tracker_mimetype_info_get_module:
  * @info: a #TrackerMimetypeInfo
  * @extract_func: (out): (allow-none): return value for the extraction function
- * @thread_awareness: (out): (allow-none): thread awareness of the extractor module
  *
  * Returns the #GModule that @info is currently pointing to, if @extract_func is
  * not %NULL, it will be filled in with the pointer to the metadata extraction
- * function. If @thread_awareness is not %NULL, it will be filled in with the
- * module thread awareness description.
+ * function.
  *
  * Returns: The %GModule currently pointed to by @info.
  *
@@ -543,8 +537,7 @@ tracker_extract_module_manager_get_mimetype_handlers (const gchar *mimetype)
  **/
 GModule *
 tracker_mimetype_info_get_module (TrackerMimetypeInfo          *info,
-                                  TrackerExtractMetadataFunc   *extract_func,
-                                  TrackerModuleThreadAwareness *thread_awareness)
+                                  TrackerExtractMetadataFunc   *extract_func)
 {
        g_return_val_if_fail (info != NULL, NULL);
 
@@ -556,10 +549,6 @@ tracker_mimetype_info_get_module (TrackerMimetypeInfo          *info,
                *extract_func = info->cur_module_info->extract_func;
        }
 
-       if (thread_awareness) {
-               *thread_awareness = info->cur_module_info->thread_awareness;
-       }
-
        return info->cur_module_info->module;
 }
 
diff --git a/src/libtracker-extract/tracker-module-manager.h b/src/libtracker-extract/tracker-module-manager.h
index f11618a..e49712b 100644
--- a/src/libtracker-extract/tracker-module-manager.h
+++ b/src/libtracker-extract/tracker-module-manager.h
@@ -32,37 +32,9 @@
 
 G_BEGIN_DECLS
 
-/**
- * TrackerModuleThreadAwareness:
- * @TRACKER_MODULE_NONE: Extractions are completed in the main event
- * loop.
- * @TRACKER_MODULE_MAIN_THREAD: Extractions will be dispatched in the
- * main thread.
- * @TRACKER_MODULE_SINGLE_THREAD: Extractions will be dispatched in a
- * separate thread which is not the main thread. This means a new
- * thread is created and used for all extractions with this value.
- * @TRACKER_MODULE_MULTI_THREAD: A thread pool is used for all
- * extractions of this module. This requires that the module is thread
- * aware.
- *
- * Enumerates the different types of thread awareness which extractor
- * modules need to be aware of. This is useful to know because it
- * changes the way we queue and notify extractions with modules for
- * metadata from files.
- *
- * Since: 0.14
- **/
-typedef enum {
-       TRACKER_MODULE_NONE,
-       TRACKER_MODULE_MAIN_THREAD,
-       TRACKER_MODULE_SINGLE_THREAD,
-       TRACKER_MODULE_MULTI_THREAD
-} TrackerModuleThreadAwareness;
-
 typedef struct _TrackerMimetypeInfo TrackerMimetypeInfo;
 
-typedef gboolean (* TrackerExtractInitFunc)     (TrackerModuleThreadAwareness  *thread_awareness_ret,
-                                                 GError                       **error);
+typedef gboolean (* TrackerExtractInitFunc)     (GError **error);
 typedef void     (* TrackerExtractShutdownFunc) (void);
 
 typedef gboolean (* TrackerExtractMetadataFunc) (TrackerExtractInfo *info);
@@ -81,8 +53,7 @@ TrackerMimetypeInfo * tracker_extract_module_manager_get_mimetype_handlers  (con
 GStrv                 tracker_extract_module_manager_get_fallback_rdf_types (const gchar *mimetype);
 
 GModule * tracker_mimetype_info_get_module (TrackerMimetypeInfo          *info,
-                                            TrackerExtractMetadataFunc   *extract_func,
-                                            TrackerModuleThreadAwareness *thread_awareness);
+                                            TrackerExtractMetadataFunc   *extract_func);
 gboolean  tracker_mimetype_info_iter_next  (TrackerMimetypeInfo          *info);
 void      tracker_mimetype_info_free       (TrackerMimetypeInfo          *info);
 
diff --git a/src/tracker-extract/tracker-extract-text.c b/src/tracker-extract/tracker-extract-text.c
index 857daa4..abcf403 100644
--- a/src/tracker-extract/tracker-extract-text.c
+++ b/src/tracker-extract/tracker-extract-text.c
@@ -81,14 +81,6 @@ get_file_content (GFile *file,
 }
 
 G_MODULE_EXPORT gboolean
-tracker_extract_module_init (TrackerModuleThreadAwareness  *thread_awareness_ret,
-                             GError                       **error)
-{
-       *thread_awareness_ret = TRACKER_MODULE_MULTI_THREAD;
-       return TRUE;
-}
-
-G_MODULE_EXPORT gboolean
 tracker_extract_get_metadata (TrackerExtractInfo *info)
 {
        TrackerResource *metadata;
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index b32f34f..a1d293e 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -521,7 +521,7 @@ get_metadata (TrackerExtractTask *task)
        return FALSE;
 }
 
-static void
+static gpointer
 single_thread_get_metadata (GAsyncQueue *queue)
 {
        while (TRUE) {
@@ -534,6 +534,8 @@ single_thread_get_metadata (GAsyncQueue *queue)
 #endif /* THREAD_ENABLE_TRACE */
                get_metadata (task);
        }
+
+       return NULL;
 }
 
 /* This function is executed in the main thread, decides the
@@ -543,9 +545,9 @@ single_thread_get_metadata (GAsyncQueue *queue)
 static gboolean
 dispatch_task_cb (TrackerExtractTask *task)
 {
-       TrackerModuleThreadAwareness thread_awareness;
        TrackerExtractPrivate *priv;
        GError *error = NULL;
+       GAsyncQueue *async_queue;
        GModule *module;
 
 #ifdef THREAD_ENABLE_TRACE
@@ -595,7 +597,7 @@ dispatch_task_cb (TrackerExtractTask *task)
                return FALSE;
        }
 
-       task->cur_module = module = tracker_mimetype_info_get_module (task->mimetype_handlers, 
&task->cur_func, &thread_awareness);
+       task->cur_module = module = tracker_mimetype_info_get_module (task->mimetype_handlers, 
&task->cur_func);
 
        if (!task->cur_func) {
                g_warning ("Discarding task, no module able to handle '%s'", task->file);
@@ -604,73 +606,33 @@ dispatch_task_cb (TrackerExtractTask *task)
                return FALSE;
        }
 
-       switch (thread_awareness) {
-       case TRACKER_MODULE_NONE:
-               /* Error out */
-               g_task_return_new_error (G_TASK (task->res),
-                                        tracker_extract_error_quark (),
-                                        TRACKER_EXTRACT_ERROR_NO_EXTRACTOR,
-                                        "Module '%s' initialization failed",
-                                        g_module_name (module));
-               extract_task_free (task);
-               break;
-       case TRACKER_MODULE_MAIN_THREAD:
-               /* Dispatch the task right away in this thread */
-#ifdef THREAD_ENABLE_TRACE
-               g_debug ("Thread:%p (Main) <-- '%s': Dispatching in main thread",
-                        g_thread_self(), task->file);
-#endif /* THREAD_ENABLE_TRACE */
-               get_metadata (task);
-               break;
-       case TRACKER_MODULE_SINGLE_THREAD: {
-               GAsyncQueue *async_queue;
-
-               async_queue = g_hash_table_lookup (priv->single_thread_extractors, module);
-
-               if (!async_queue) {
-                       GThread *thread;
-
-                       /* No thread created yet for this module, create it
-                        * together with the async queue used to pass data to it
-                        */
-                       async_queue = g_async_queue_new ();
-                       thread = g_thread_try_new ("single",
-                                                  (GThreadFunc) single_thread_get_metadata,
-                                                  g_async_queue_ref (async_queue),
-                                                  &error);
-                       if (!thread) {
-                               g_task_return_error (G_TASK (task->res), error);
-                               extract_task_free (task);
-                               return FALSE;
-                       }
+       async_queue = g_hash_table_lookup (priv->single_thread_extractors, module);
 
-                       /* We won't join the thread, so just unref it here */
-                       g_object_unref (thread);
+       if (!async_queue) {
+               GThread *thread;
 
-                       g_hash_table_insert (priv->single_thread_extractors, module, async_queue);
-               }
-
-               g_async_queue_push (async_queue, task);
-               break;
-       }
-       case TRACKER_MODULE_MULTI_THREAD:
-               /* Put task in thread pool */
-#ifdef THREAD_ENABLE_TRACE
-               g_debug ("Thread:%p (Main) --> '%s': Dispatching in thread pool",
-                        g_thread_self(), task->file);
-#endif /* THREAD_ENABLE_TRACE */
-               g_thread_pool_push (priv->thread_pool, task, &error);
-
-               if (error) {
+               /* No thread created yet for this module, create it
+                * together with the async queue used to pass data to it
+                */
+               async_queue = g_async_queue_new ();
+               thread = g_thread_try_new ("single",
+                                          (GThreadFunc) single_thread_get_metadata,
+                                          g_async_queue_ref (async_queue),
+                                          &error);
+               if (!thread) {
                        g_task_return_error (G_TASK (task->res), error);
                        extract_task_free (task);
-
                        return FALSE;
                }
 
-               break;
+               /* We won't join the thread, so just unref it here */
+               g_thread_unref (thread);
+
+               g_hash_table_insert (priv->single_thread_extractors, module, async_queue);
        }
 
+       g_async_queue_push (async_queue, task);
+
        return FALSE;
 }
 
@@ -767,7 +729,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 
        task->mimetype_handlers = tracker_extract_module_manager_get_mimetype_handlers (task->mimetype);
        if (task->mimetype_handlers) {
-               task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers, 
&task->cur_func, NULL);
+               task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers, 
&task->cur_func);
        }
 
        while (task->cur_func) {
@@ -820,8 +782,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                        }
 
                        task->cur_module = tracker_mimetype_info_get_module (task->mimetype_handlers,
-                                                                            &task->cur_func,
-                                                                            NULL);
+                                                                            &task->cur_func);
                }
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]