[tracker/tracker-0.12] libtracker-common: Use g_mutex_(init|clear) if GLib >= 2.31
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.12] libtracker-common: Use g_mutex_(init|clear) if GLib >= 2.31
- Date: Fri, 16 Dec 2011 16:49:20 +0000 (UTC)
commit 6c896d4fcc5e0a29c5c6c529bf0e4cfe546f4a44
Author: Aleksander Morgado <aleksander lanedo com>
Date: Fri Dec 16 11:05:26 2011 +0100
libtracker-common: Use g_mutex_(init|clear) if GLib >= 2.31
Since 2.31, g_mutex_new() and g_mutex_free() are deprecated.
src/libtracker-common/tracker-language.c | 36 +++++++++++++++++++++++++++--
src/libtracker-common/tracker-log.c | 24 +++++++++++++++++++-
2 files changed, 56 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-common/tracker-language.c b/src/libtracker-common/tracker-language.c
index d06d3ab..66e389a 100644
--- a/src/libtracker-common/tracker-language.c
+++ b/src/libtracker-common/tracker-language.c
@@ -39,7 +39,11 @@ struct _TrackerLanguagePriv {
gboolean enable_stemmer;
gchar *language_code;
+#if GLIB_CHECK_VERSION (2,31,0)
+ GMutex stemmer_mutex;
+#else
GMutex *stemmer_mutex;
+#endif
gpointer stemmer;
};
@@ -134,8 +138,11 @@ tracker_language_init (TrackerLanguage *language)
g_str_equal,
g_free,
NULL);
-
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_init (&priv->stemmer_mutex);
+#else
priv->stemmer_mutex = g_mutex_new ();
+#endif
stem_language = tracker_language_get_name_by_code (NULL);
priv->stemmer = sb_stemmer_new (stem_language, NULL);
@@ -148,13 +155,21 @@ language_finalize (GObject *object)
priv = GET_PRIV (object);
+#if GLIB_CHECK_VERSION (2,31,0)
+ if (priv->stemmer) {
+ g_mutex_lock (&priv->stemmer_mutex);
+ sb_stemmer_delete (priv->stemmer);
+ g_mutex_unlock (&priv->stemmer_mutex);
+ }
+ g_mutex_clear (&priv->stemmer_mutex);
+#else
if (priv->stemmer) {
g_mutex_lock (priv->stemmer_mutex);
sb_stemmer_delete (priv->stemmer);
g_mutex_unlock (priv->stemmer_mutex);
}
-
g_mutex_free (priv->stemmer_mutex);
+#endif
if (priv->stop_words) {
g_hash_table_unref (priv->stop_words);
@@ -311,7 +326,11 @@ language_set_stopword_list (TrackerLanguage *language,
stem_language = tracker_language_get_name_by_code (language_code);
stem_language_lower = g_ascii_strdown (stem_language, -1);
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_lock (&priv->stemmer_mutex);
+#else
g_mutex_lock (priv->stemmer_mutex);
+#endif
if (priv->stemmer) {
sb_stemmer_delete (priv->stemmer);
@@ -323,7 +342,11 @@ language_set_stopword_list (TrackerLanguage *language,
stem_language_lower);
}
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_unlock (&priv->stemmer_mutex);
+#else
g_mutex_unlock (priv->stemmer_mutex);
+#endif
g_free (stem_language_lower);
}
@@ -519,13 +542,21 @@ tracker_language_stem_word (TrackerLanguage *language,
return g_strndup (word, word_length);
}
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_lock (&priv->stemmer_mutex);
+#else
g_mutex_lock (priv->stemmer_mutex);
+#endif
stem_word = (const gchar*) sb_stemmer_stem (priv->stemmer,
(guchar*) word,
word_length);
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_unlock (&priv->stemmer_mutex);
+#else
g_mutex_unlock (priv->stemmer_mutex);
+#endif
return g_strdup (stem_word);
}
@@ -556,4 +587,3 @@ tracker_language_get_name_by_code (const gchar *language_code)
return "";
}
-
diff --git a/src/libtracker-common/tracker-log.c b/src/libtracker-common/tracker-log.c
index 012606f..8334012 100644
--- a/src/libtracker-common/tracker-log.c
+++ b/src/libtracker-common/tracker-log.c
@@ -35,11 +35,16 @@
#include "tracker-file-utils.h"
static gboolean initialized;
-static GMutex *mutex;
static FILE *fd;
static gint verbosity;
static guint log_handler_id;
+#if GLIB_CHECK_VERSION (2,31,0)
+static GMutex mutex;
+#else
+static GMutex *mutex;
+#endif
+
static inline void
log_output (const gchar *domain,
GLogLevelFlags log_level,
@@ -56,7 +61,11 @@ log_output (const gchar *domain,
g_return_if_fail (message != NULL && message[0] != '\0');
/* Ensure file logging is thread safe */
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_lock (&mutex);
+#else
g_mutex_lock (mutex);
+#endif
/* Check log size, 10MiB limit */
if (size > (10 << 20) && fd) {
@@ -113,7 +122,11 @@ log_output (const gchar *domain,
g_free (output);
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_unlock (&mutex);
+#else
g_mutex_unlock (mutex);
+#endif
}
static void
@@ -185,7 +198,12 @@ tracker_log_init (gint this_verbosity,
}
verbosity = CLAMP (this_verbosity, 0, 3);
+
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_init (&mutex);
+#else
mutex = g_mutex_new ();
+#endif
switch (this_verbosity) {
/* Log level 3: EVERYTHING */
@@ -256,7 +274,11 @@ tracker_log_shutdown (void)
fclose (fd);
}
+#if GLIB_CHECK_VERSION (2,31,0)
+ g_mutex_clear (&mutex);
+#else
g_mutex_free (mutex);
+#endif
initialized = FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]