[tracker/wip/carlosg/hashtable-ownership: 3/3] libtracker-data: Add locking around graphs hashtable




commit b093bbe653eeef1f8a3dff1690200f86504ee62f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Dec 5 23:40:48 2021 +0100

    libtracker-data: Add locking around graphs hashtable
    
    This may be changed from the updates thread, so it is better to
    make this protected by a mutex.

 src/libtracker-data/tracker-data-manager.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a78996fd0..ee06c93db 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -82,6 +82,7 @@ struct _TrackerDataManager {
 
        GHashTable *transaction_graphs;
        GHashTable *graphs;
+       GMutex graphs_lock;
 
        /* Cached remote connections */
        GMutex connections_lock;
@@ -150,6 +151,7 @@ tracker_data_manager_init (TrackerDataManager *manager)
 {
        manager->generation = 1;
        g_mutex_init (&manager->connections_lock);
+       g_mutex_init (&manager->graphs_lock);
 }
 
 GQuark
@@ -209,11 +211,15 @@ tracker_data_manager_get_graphs (TrackerDataManager *manager,
 {
        GHashTable *ht;
 
+       g_mutex_lock (&manager->graphs_lock);
+
        if (manager->transaction_graphs && in_transaction)
                ht = g_hash_table_ref (manager->transaction_graphs);
        else
                ht = g_hash_table_ref (manager->graphs);
 
+       g_mutex_unlock (&manager->graphs_lock);
+
        return ht;
 }
 
@@ -4778,6 +4784,7 @@ tracker_data_manager_finalize (GObject *object)
        g_clear_pointer (&manager->graphs, g_hash_table_unref);
        g_free (manager->status);
        g_mutex_clear (&manager->connections_lock);
+       g_mutex_clear (&manager->graphs_lock);
 
        G_OBJECT_CLASS (tracker_data_manager_parent_class)->finalize (object);
 }
@@ -5162,12 +5169,16 @@ tracker_data_manager_get_generation (TrackerDataManager *manager)
 void
 tracker_data_manager_commit_graphs (TrackerDataManager *manager)
 {
+       g_mutex_lock (&manager->graphs_lock);
+
        if (manager->transaction_graphs) {
                g_clear_pointer (&manager->graphs, g_hash_table_unref);
                manager->graphs = manager->transaction_graphs;
                manager->transaction_graphs = NULL;
                manager->generation++;
        }
+
+       g_mutex_unlock (&manager->graphs_lock);
 }
 
 void


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