summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2017-11-25 14:14:32 +0100
committerCarlos Garnacho <carlosg@gnome.org>2018-07-20 18:27:32 +0200
commitadfa177cb1c38bf3452d16ea66195cf0fade4068 (patch)
tree681c23bd3e8072fb965cee8965176b78cce488fd
parent38e362da82eef861a07b464cfc2d91f9539a74f8 (diff)
downloadtracker-adfa177cb1c38bf3452d16ea66195cf0fade4068.tar.gz
tracker-store: Protect ready writeback events with mutex
Just like with ready GraphUpdated events, this will be potentially accessed by both the thread performing updates, and the thread doing the DBus dispatching and signaling. Just like there, the chances of contention are rather low, since emission is checked just once per second by default.
-rw-r--r--src/tracker-store/tracker-writeback.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index 5bba19020..1edc3e2dd 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -27,8 +27,12 @@
#include "tracker-writeback.h"
typedef struct {
+ /* Accessed by updates thread */
GHashTable *allowances;
GHashTable *pending_events;
+
+ /* Accessed by both updates and dbus threads */
+ GMutex mutex;
GHashTable *ready_events;
} WritebackPrivate;
@@ -119,8 +123,10 @@ tracker_writeback_get_ready (void)
g_return_val_if_fail (private != NULL, NULL);
+ g_mutex_lock (&private->mutex);
events = private->ready_events;
private->ready_events = NULL;
+ g_mutex_unlock (&private->mutex);
return events;
}
@@ -150,6 +156,7 @@ tracker_writeback_init (TrackerDataManager *data_manager,
g_return_if_fail (private == NULL);
private = g_new0 (WritebackPrivate, 1);
+ g_mutex_init (&private->mutex);
private->allowances = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
@@ -196,6 +203,8 @@ tracker_writeback_transact (void)
if (!private->pending_events)
return;
+ g_mutex_lock (&private->mutex);
+
if (!private->ready_events) {
private->ready_events = g_hash_table_new_full (g_direct_hash, g_direct_equal,
(GDestroyNotify) NULL,
@@ -208,6 +217,8 @@ tracker_writeback_transact (void)
g_hash_table_insert (private->ready_events, key, value);
g_hash_table_iter_remove (&iter);
}
+
+ g_mutex_unlock (&private->mutex);
}
void