[tracker] libtracker-sparql, -common: GConfClient's get_default isn't thread-safe, workaround this issue



commit a3d1504d8c3ff35654127bfd037caa1167d9ebec
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Mar 22 12:52:03 2011 +0100

    libtracker-sparql, -common: GConfClient's get_default isn't thread-safe, workaround this issue
    
    Fixes NB#238447.

 configure.ac                           |    3 +++
 src/libtracker-common/tracker-locale.c |   12 ++++++++++++
 src/libtracker-sparql/Makefile.am      |    3 ++-
 src/libtracker-sparql/tracker-init.c   |   20 ++++++++++++++++++++
 4 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 605e489..acb6277 100644
--- a/configure.ac
+++ b/configure.ac
@@ -594,6 +594,9 @@ if test "x$enable_maemo" = "xyes" ; then
    LIBTRACKER_COMMON_CFLAGS="$LIBTRACKER_COMMON_CFLAGS $GCONF_CFLAGS"
    LIBTRACKER_COMMON_LIBS="$LIBTRACKER_COMMON_LIBS $GCONF_LIBS"
 
+   LIBTRACKER_SPARQL_CFLAGS="$LIBTRACKER_SPARQL_CFLAGS $GCONF_CFLAGS"
+   LIBTRACKER_SPARQL_LIBS="$LIBTRACKER_SPARQL_LIBS $GCONF_LIBS"
+
    if test "x$have_gconf" != "xyes"; then
       AC_MSG_ERROR([Couldn't find gconf, needed when enabling maemo support])
    fi
diff --git a/src/libtracker-common/tracker-locale.c b/src/libtracker-common/tracker-locale.c
index 73a6b91..3a00cb1 100644
--- a/src/libtracker-common/tracker-locale.c
+++ b/src/libtracker-common/tracker-locale.c
@@ -31,6 +31,18 @@
 #endif /* HAVE_MAEMO */
 
 #ifdef HAVE_MAEMO
+
+/* In src/libtracker-sparql/tracker-init.c you'll find a first call to
+ * gconf_client_get_default() in a function that has the GCC specific
+ * construction attribute. This is there because GConfClient isn't thread-safe
+ * or at least not "first call is in thread vs. mainloop"-safe. The reason
+ * why it must be in libtracker-sparql instead of here is because this code
+ * is entered using g_module_open (dlopen) by tracker_sparql_backend_load_
+ * plugins_from_path: the construction attribute would only be detected at
+ * dlopen, which would be in the thread that calls load_plugins_from_path
+ * caused by a tracker_sparql_connection_get_async. It's a bit unfortunate
+ * and perhaps ugly, but fortunately we only need it in HAVE_MAEMO */
+
 /* Mutex to sync access to the current locale values */
 static GStaticMutex locales_mutex = G_STATIC_MUTEX_INIT;
 static GStaticMutex subscribers_mutex = G_STATIC_MUTEX_INIT;
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index 7795e03..38f9512 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -28,7 +28,8 @@ libtracker_sparql_ TRACKER_API_VERSION@_la_SOURCES =   \
 	tracker-cursor.vala                            \
 	tracker-backend.vala                           \
 	tracker-utils.vala                             \
-	tracker-uri.c
+	tracker-uri.c                                  \
+	tracker-init.c
 
 libtracker_sparql_ TRACKER_API_VERSION@_la_LIBADD =    \
 	$(BUILD_LIBS)                                  \
diff --git a/src/libtracker-sparql/tracker-init.c b/src/libtracker-sparql/tracker-init.c
new file mode 100644
index 0000000..511c79e
--- /dev/null
+++ b/src/libtracker-sparql/tracker-init.c
@@ -0,0 +1,20 @@
+#include "config.h"
+
+#ifdef HAVE_MAEMO
+
+/* Information about this chunk of code at
+ * src/libtracker-common/tracker-locale.c */
+
+#include <glib.h>
+#include <gconf/gconf-client.h>
+
+__attribute__ ((constructor))
+static void
+init_gconf_client (void)
+{
+	g_type_init ();
+	gconf_client_get_default ();
+}
+
+#endif /* HAVE_MAEMO */
+



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