[tracker/wip/carlosg/tracker-3.0-api-breaks: 90/100] libtracker-direct: Unref notifiers before closing data manager



commit f6d101f53862acc9ee96cdc51a6c2d5c4a1276cc
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Feb 4 23:22:46 2020 +0100

    libtracker-direct: Unref notifiers before closing data manager
    
    The detach_notifier() function accesses the priv->data_manager object.
    In order to untangle this, shuffle the code between close() and dispose()
    so the data manager and all related data get freed on close(), and we
    ensure tracker_sparql_connection_close() gets called on dispose().
    
    The notifiers themselves are then freed on close(), before the data manager
    gets destroyed.

 src/libtracker-direct/tracker-direct.c     | 67 +++++++++++++-----------------
 src/libtracker-sparql/tracker-connection.c | 13 +++++-
 2 files changed, 41 insertions(+), 39 deletions(-)
---
diff --git a/src/libtracker-direct/tracker-direct.c b/src/libtracker-direct/tracker-direct.c
index 842510055..4db502bf7 100644
--- a/src/libtracker-direct/tracker-direct.c
+++ b/src/libtracker-direct/tracker-direct.c
@@ -525,33 +525,6 @@ weak_ref_notify (gpointer  data,
        detach_notifier (conn, (TrackerNotifier *) prev_location);
 }
 
-static void
-tracker_direct_connection_dispose (GObject *object)
-{
-       TrackerDirectConnectionPrivate *priv;
-       TrackerDirectConnection *conn;
-
-       conn = TRACKER_DIRECT_CONNECTION (object);
-       priv = tracker_direct_connection_get_instance_private (conn);
-
-       if (priv->update_thread) {
-               g_thread_pool_free (priv->update_thread, TRUE, TRUE);
-               priv->update_thread = NULL;
-       }
-
-       if (priv->select_pool) {
-               g_thread_pool_free (priv->select_pool, TRUE, FALSE);
-               priv->select_pool = NULL;
-       }
-
-       if (priv->data_manager) {
-               tracker_data_manager_shutdown (priv->data_manager);
-               g_clear_object (&priv->data_manager);
-       }
-
-       G_OBJECT_CLASS (tracker_direct_connection_parent_class)->dispose (object);
-}
-
 static void
 tracker_direct_connection_finalize (GObject *object)
 {
@@ -561,15 +534,6 @@ tracker_direct_connection_finalize (GObject *object)
        conn = TRACKER_DIRECT_CONNECTION (object);
        priv = tracker_direct_connection_get_instance_private (conn);
 
-       while (priv->notifiers) {
-               TrackerNotifier *notifier = priv->notifiers->data;
-
-               g_object_weak_unref (G_OBJECT (notifier),
-                                    weak_ref_notify,
-                                    conn);
-               detach_notifier (conn, notifier);
-       }
-
        g_clear_object (&priv->store);
        g_clear_object (&priv->ontology);
        g_clear_object (&priv->namespace_manager);
@@ -925,7 +889,35 @@ tracker_direct_connection_create_notifier (TrackerSparqlConnection *self,
 static void
 tracker_direct_connection_close (TrackerSparqlConnection *self)
 {
-       g_object_run_dispose (G_OBJECT (self));
+       TrackerDirectConnectionPrivate *priv;
+       TrackerDirectConnection *conn;
+
+       conn = TRACKER_DIRECT_CONNECTION (self);
+       priv = tracker_direct_connection_get_instance_private (conn);
+
+       if (priv->update_thread) {
+               g_thread_pool_free (priv->update_thread, TRUE, TRUE);
+               priv->update_thread = NULL;
+       }
+
+       if (priv->select_pool) {
+               g_thread_pool_free (priv->select_pool, TRUE, FALSE);
+               priv->select_pool = NULL;
+       }
+
+       while (priv->notifiers) {
+               TrackerNotifier *notifier = priv->notifiers->data;
+
+               g_object_weak_unref (G_OBJECT (notifier),
+                                    weak_ref_notify,
+                                    conn);
+               detach_notifier (conn, notifier);
+       }
+
+       if (priv->data_manager) {
+               tracker_data_manager_shutdown (priv->data_manager);
+               g_clear_object (&priv->data_manager);
+       }
 }
 
 static void
@@ -938,7 +930,6 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass)
        sparql_connection_class = TRACKER_SPARQL_CONNECTION_CLASS (klass);
 
        object_class->finalize = tracker_direct_connection_finalize;
-       object_class->dispose = tracker_direct_connection_dispose;
        object_class->set_property = tracker_direct_connection_set_property;
        object_class->get_property = tracker_direct_connection_get_property;
 
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index 043e691e8..d5ba6ce31 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -31,9 +31,20 @@ tracker_sparql_connection_init (TrackerSparqlConnection *connection)
 {
 }
 
+static void
+tracker_sparql_connection_dispose (GObject *object)
+{
+       tracker_sparql_connection_close (TRACKER_SPARQL_CONNECTION (object));
+
+       G_OBJECT_CLASS (tracker_sparql_connection_parent_class)->dispose (object);
+}
+
 static void
 tracker_sparql_connection_class_init (TrackerSparqlConnectionClass *klass)
 {
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->dispose = tracker_sparql_connection_dispose;
 }
 
 /* The constructor functions are defined in the libtracker-sparql-backend, but
@@ -555,7 +566,7 @@ tracker_sparql_connection_create_notifier (TrackerSparqlConnection *connection,
  *
  * This call is blocking. All pending updates will be flushed, and the
  * store databases will be closed orderly. All ongoing SELECT queries
- * will be cancelled.
+ * will be cancelled. Notifiers will no longer emit events.
  *
  * Since: 3.0
  */


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