[tracker/wip/carlosg/tracker-3.0-api-breaks: 71/79] libtracker-sparql: Make TrackerNotifier queries asynchronous
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/tracker-3.0-api-breaks: 71/79] libtracker-sparql: Make TrackerNotifier queries asynchronous
- Date: Mon, 27 Jan 2020 12:24:08 +0000 (UTC)
commit e0010f6b8b75b941994ec12bc419bfbdda4f7227
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jan 27 00:19:54 2020 +0100
libtracker-sparql: Make TrackerNotifier queries asynchronous
Synchronous queries are very untimely here, since the events are
handled within TrackerDirectConnection mutex, triggering deadlocks
here.
Doing the queries asynchronously defers this to a thread pool, so
the mutex will be contended from 2 separate threads, if at all.
src/libtracker-sparql/tracker-notifier.c | 50 ++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index a1381a817..db05dc1fb 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -342,25 +342,22 @@ create_extra_info_query (TrackerNotifier *notifier,
}
static void
-tracker_notifier_query_extra_info (TrackerNotifier *notifier,
- TrackerNotifierEventCache *cache)
+query_extra_info_cb (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ TrackerNotifierEventCache *cache = user_data;
+ TrackerSparqlConnection *conn;
TrackerNotifierPrivate *priv;
TrackerSparqlCursor *cursor;
TrackerNotifierEvent *event;
GSequenceIter *iter;
- gchar *sparql;
gint col;
gint64 id;
- sparql = create_extra_info_query (notifier, cache);
- if (!sparql)
- return;
-
- priv = tracker_notifier_get_instance_private (notifier);
- cursor = tracker_sparql_connection_query (priv->connection, sparql,
- NULL, NULL);
- g_free (sparql);
+ priv = tracker_notifier_get_instance_private (cache->notifier);
+ conn = TRACKER_SPARQL_CONNECTION (object);
+ cursor = tracker_sparql_connection_query_finish (conn, res, NULL);
iter = g_sequence_get_begin_iter (cache->sequence);
@@ -386,6 +383,28 @@ tracker_notifier_query_extra_info (TrackerNotifier *notifier,
}
g_object_unref (cursor);
+
+ tracker_notifier_emit_events (cache);
+ _tracker_notifier_event_cache_free (cache);
+}
+
+static void
+tracker_notifier_query_extra_info (TrackerNotifier *notifier,
+ TrackerNotifierEventCache *cache)
+{
+ TrackerNotifierPrivate *priv;
+ gchar *sparql;
+
+ sparql = create_extra_info_query (notifier, cache);
+ if (!sparql)
+ return;
+
+ priv = tracker_notifier_get_instance_private (notifier);
+ tracker_sparql_connection_query_async (priv->connection, sparql,
+ NULL,
+ query_extra_info_cb,
+ cache);
+ g_free (sparql);
}
void
@@ -397,11 +416,12 @@ _tracker_notifier_event_cache_flush_events (TrackerNotifierEventCache *cache)
if (g_sequence_is_empty (cache->sequence))
_tracker_notifier_event_cache_free (cache);
- if (priv->flags & TRACKER_NOTIFIER_FLAG_QUERY_URN)
+ if (priv->flags & TRACKER_NOTIFIER_FLAG_QUERY_URN) {
tracker_notifier_query_extra_info (notifier, cache);
-
- tracker_notifier_emit_events (cache);
- _tracker_notifier_event_cache_free (cache);
+ } else {
+ tracker_notifier_emit_events (cache);
+ _tracker_notifier_event_cache_free (cache);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]