diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2023-04-10 13:57:17 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2023-05-15 09:30:52 +0000 |
commit | 7d10deb89ac7e68883fa2286e95036deeab35efc (patch) | |
tree | 94f2e600beeadab182d535eb1687d7bf4ae2f5ee /src | |
parent | 1ea0c72ec7a63359db73660943f3fb912be41c7e (diff) | |
download | tracker-7d10deb89ac7e68883fa2286e95036deeab35efc.tar.gz |
libtracker-sparql: Improve threading guarantees of TrackerNotifier
Make the TrackerNotifier::events signal ensured to be emitted in the
same main context that created the TrackerNotifier. This is coherent
with other threaded objects that have communication through signals
(e.g. GDBusProxy).
Notably, it is already expected to behave this way in tracker-miners.
Since the tracker-miner-fs-3 D-Bus endpoint is managed on a distinct
context/thread that should also handle the proxying of notifier events
without involvement of the main thread/context.
Diffstat (limited to 'src')
-rw-r--r-- | src/libtracker-sparql/tracker-notifier.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c index 1ac26e019..f67c7a3d3 100644 --- a/src/libtracker-sparql/tracker-notifier.c +++ b/src/libtracker-sparql/tracker-notifier.c @@ -48,6 +48,9 @@ * Similarly, when receiving an event of type %TRACKER_NOTIFIER_EVENT_UPDATE, * the resource will have already changed, so the data previous to the update is * no longer available. + * + * The [signal@Tracker.Notifier::events] signal is emitted in the thread-default + * main context of the thread where the `TrackerNotifier` instance was created. */ #include "config.h" @@ -79,6 +82,7 @@ struct _TrackerNotifierPrivate { GCancellable *cancellable; TrackerSparqlStatement *local_statement; GAsyncQueue *queue; + GMainContext *main_context; gint n_local_statement_slots; guint querying : 1; guint urn_query_disabled : 1; @@ -381,10 +385,19 @@ tracker_notifier_emit_events (TrackerNotifierEventCache *cache) static void tracker_notifier_emit_events_in_idle (TrackerNotifierEventCache *cache) { - g_idle_add_full (G_PRIORITY_DEFAULT, - (GSourceFunc) tracker_notifier_emit_events, - cache, - (GDestroyNotify) _tracker_notifier_event_cache_free); + TrackerNotifier *notifier = cache->notifier; + TrackerNotifierPrivate *priv; + GSource *source; + + priv = tracker_notifier_get_instance_private (notifier); + + source = g_idle_source_new (); + g_source_set_callback (source, + (GSourceFunc) tracker_notifier_emit_events, + cache, + (GDestroyNotify) _tracker_notifier_event_cache_free); + g_source_attach (source, priv->main_context); + g_source_unref (source); } static gchar * @@ -795,6 +808,7 @@ tracker_notifier_init (TrackerNotifier *notifier) (GDestroyNotify) tracker_notifier_subscription_free); priv->cancellable = g_cancellable_new (); priv->queue = g_async_queue_new (); + priv->main_context = g_main_context_get_thread_default (); } /** |