[tracker/dbus-fd-experiment-gio: 23/41] Workaround a race condition in libdbus
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment-gio: 23/41] Workaround a race condition in libdbus
- Date: Thu, 10 Jun 2010 22:54:09 +0000 (UTC)
commit 584a025813ae4f12965333e38d97173ddbb167b3
Author: Adrien Bustany <abustany gnome org>
Date: Thu Jun 3 20:29:45 2010 -0400
Workaround a race condition in libdbus
The dbus_pending_call_block function cannot be used safely from another
thread than the main thread (ie. the one which is doing DBus messages
dispatching). This commit works around this issue using duct tape,
chewing gum and strong glue.
More info on the bug at
http://lists.freedesktop.org/archives/dbus/2009-March/011105.html
src/libtracker-client/tracker.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 0f19db2..e6492be 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -38,6 +38,9 @@
#include "tracker-resources-glue.h"
#include "tracker-statistics-glue.h"
+/* sleep delay to emulate dbus_pending_call_block, in us */
+#define NOT_TOO_SHORT_DELAY 1000
+
/**
* SECTION:tracker
* @short_description: A client library for querying and inserting
@@ -977,7 +980,10 @@ sparql_update_fast (TrackerClient *client,
g_free (query_size_buffer);
- dbus_pending_call_block (call);
+ /* dbus_pending_call_block (call); */
+ while (!dbus_pending_call_get_completed (call)) {
+ g_usleep (NOT_TOO_SHORT_DELAY);
+ }
reply = dbus_pending_call_steal_reply (call);
@@ -1538,7 +1544,17 @@ tracker_resources_sparql_query_iterate (TrackerClient *client,
iterator->has_next = TRUE;
}
- dbus_pending_call_block (call);
+ /* dbus_pending_call_block (call); */
+ /* This is a ugly workaround for a race condition in libdbus when you're
+ * calling dbus_pending_call_block from a thread which is not the thread
+ * where the DBus dispatch call happens. This is the case when the function
+ * is run from tracker_resources_sparql_query_iterate_async.
+ * See http://lists.freedesktop.org/archives/dbus/2009-March/011105.html
+ * for a lengthy explication
+ */
+ while (!dbus_pending_call_get_completed (call)) {
+ g_usleep (NOT_TOO_SHORT_DELAY);
+ }
reply = dbus_pending_call_steal_reply (call);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]