[tracker/compilation-warnings: 3/13] tracker-extract: Use g_(mutex|cond)_(init|clear) if GLib >= 2.31



commit 4153ed410105f412e44200fb4b1cdf550eebadcd
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Dec 16 11:16:21 2011 +0100

    tracker-extract: Use g_(mutex|cond)_(init|clear) if GLib >= 2.31
    
    Since 2.31, g_mutex_new(), g_mutex_free(), g_cond_new(), g_cond_free() are
    deprecated.

 src/tracker-extract/tracker-controller.c |   37 +++++++++++++++++++++--
 src/tracker-extract/tracker-extract.c    |   46 ++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 7 deletions(-)
---
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index a52ecbe..6c059fc 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -59,9 +59,15 @@ struct TrackerControllerPrivate {
 	guint shutdown_timeout;
 	GSource *shutdown_source;
 
+
+	GError *initialization_error;
+#if GLIB_CHECK_VERSION (2,31,0)
+	GCond initialization_cond;
+	GMutex initialization_mutex;
+#else
 	GCond *initialization_cond;
 	GMutex *initialization_mutex;
-	GError *initialization_error;
+#endif
 
 	guint initialized : 1;
 };
@@ -166,8 +172,13 @@ tracker_controller_finalize (GObject *object)
 	g_main_loop_unref (priv->main_loop);
 	g_main_context_unref (priv->context);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_cond_clear (&priv->initialization_cond);
+	g_mutex_clear (&priv->initialization_mutex);
+#else
 	g_cond_free (priv->initialization_cond);
 	g_mutex_free (priv->initialization_mutex);
+#endif
 
 	G_OBJECT_CLASS (tracker_controller_parent_class)->finalize (object);
 }
@@ -400,8 +411,13 @@ tracker_controller_init (TrackerController *controller)
 	g_signal_connect (priv->storage, "mount-point-removed",
 	                  G_CALLBACK (mount_point_removed_cb), controller);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_cond_init (&priv->initialization_cond);
+	g_mutex_init (&priv->initialization_mutex);
+#else
 	priv->initialization_cond = g_cond_new ();
 	priv->initialization_mutex = g_mutex_new ();
+#endif
 }
 
 static void
@@ -775,15 +791,23 @@ controller_notify_main_thread (TrackerController *controller,
 
 	priv = controller->priv;
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->initialization_mutex);
+#else
 	g_mutex_lock (priv->initialization_mutex);
+#endif
 
 	priv->initialized = TRUE;
 	priv->initialization_error = error;
 
 	/* Notify about the initialization */
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_cond_signal (&priv->initialization_cond);
+	g_mutex_unlock (&priv->initialization_mutex);
+#else
 	g_cond_signal (priv->initialization_cond);
-
 	g_mutex_unlock (priv->initialization_mutex);
+#endif
 }
 
 static void
@@ -980,13 +1004,18 @@ tracker_controller_start (TrackerController  *controller,
 #endif /* THREAD_ENABLE_TRACE */
 
 	/* Wait for the controller thread to notify initialization */
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->initialization_mutex);
+	while (!priv->initialized)
+		g_cond_wait (&priv->initialization_cond, &priv->initialization_mutex);
+	g_mutex_unlock (&priv->initialization_mutex);
+#else
 	g_mutex_lock (priv->initialization_mutex);
-
 	while (!priv->initialized) {
 		g_cond_wait (priv->initialization_cond, priv->initialization_mutex);
 	}
-
 	g_mutex_unlock (priv->initialization_mutex);
+#endif
 
 	/* If there was any error resulting from initialization, propagate it */
 	if (priv->initialization_error != NULL) {
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 71b6e22..ce78e1b 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -61,7 +61,11 @@ typedef struct {
 	/* used to maintain the running tasks
 	 * and stats from different threads
 	 */
+#if GLIB_CHECK_VERSION (2,31,0)
+	GMutex task_mutex;
+#else
 	GMutex *task_mutex;
+#endif
 
 	/* Thread pool for multi-threaded extractors */
 	GThreadPool *thread_pool;
@@ -140,7 +144,11 @@ tracker_extract_init (TrackerExtract *object)
 	priv->thread_pool = g_thread_pool_new ((GFunc) get_metadata,
 	                                       NULL, 10, TRUE, NULL);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_init (&priv->task_mutex);
+#else
 	priv->task_mutex = g_mutex_new ();
+#endif
 }
 
 static void
@@ -165,9 +173,11 @@ tracker_extract_finalize (GObject *object)
 
 	g_hash_table_destroy (priv->statistics_data);
 
-	if (priv->task_mutex) {
-		g_mutex_free (priv->task_mutex);
-	}
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_clear (&priv->task_mutex);
+#else
+	g_mutex_free (priv->task_mutex);
+#endif
 
 	G_OBJECT_CLASS (tracker_extract_parent_class)->finalize (object);
 }
@@ -181,7 +191,11 @@ report_statistics (GObject *object)
 
 	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->task_mutex);
+#else
 	g_mutex_lock (priv->task_mutex);
+#endif
 
 	g_message ("--------------------------------------------------");
 	g_message ("Statistics:");
@@ -214,7 +228,11 @@ report_statistics (GObject *object)
 
 	g_message ("--------------------------------------------------");
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_unlock (&priv->task_mutex);
+#else
 	g_mutex_unlock (priv->task_mutex);
+#endif
 }
 
 TrackerExtract *
@@ -255,7 +273,11 @@ notify_task_finish (TrackerExtractTask *task,
 	/* Reports and ongoing tasks may be
 	 * accessed from other threads.
 	 */
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->task_mutex);
+#else
 	g_mutex_lock (priv->task_mutex);
+#endif
 
 	stats_data = g_hash_table_lookup (priv->statistics_data,
 	                                  task->cur_module);
@@ -275,7 +297,11 @@ notify_task_finish (TrackerExtractTask *task,
 
 	priv->running_tasks = g_list_remove (priv->running_tasks, task);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_unlock (&priv->task_mutex);
+#else
 	g_mutex_unlock (priv->task_mutex);
+#endif
 }
 
 static gboolean
@@ -385,7 +411,11 @@ task_cancellable_cancelled_cb (GCancellable       *cancellable,
 	extract = task->extract;
 	priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->task_mutex);
+#else
 	g_mutex_lock (priv->task_mutex);
+#endif
 
 	if (g_list_find (priv->running_tasks, task)) {
 		g_message ("Cancelled task for '%s' was currently being "
@@ -394,7 +424,11 @@ task_cancellable_cancelled_cb (GCancellable       *cancellable,
 		_exit (0);
 	}
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_unlock (&priv->task_mutex);
+#else
 	g_mutex_unlock (priv->task_mutex);
+#endif
 }
 
 static TrackerExtractTask *
@@ -661,9 +695,15 @@ dispatch_task_cb (TrackerExtractTask *task)
 		return FALSE;
 	}
 
+#if GLIB_CHECK_VERSION (2,31,0)
+	g_mutex_lock (&priv->task_mutex);
+	priv->running_tasks = g_list_prepend (priv->running_tasks, task);
+	g_mutex_unlock (&priv->task_mutex);
+#else
 	g_mutex_lock (priv->task_mutex);
 	priv->running_tasks = g_list_prepend (priv->running_tasks, task);
 	g_mutex_unlock (priv->task_mutex);
+#endif
 
 	switch (thread_awareness) {
 	case TRACKER_MODULE_NONE:



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