summaryrefslogtreecommitdiff
path: root/common/gmounttracker.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@src.gnome.org>2007-09-13 13:31:22 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-09-13 13:31:22 +0000
commitf5dac66a4a5d50fc0221b3d5d869405b55fb6b17 (patch)
tree761b589df272e78358755f5caf4397245351a7f0 /common/gmounttracker.c
parent5b4105130d30cc15a9684282d86327eb33338bf5 (diff)
downloadgvfs-f5dac66a4a5d50fc0221b3d5d869405b55fb6b17.tar.gz
Made GMountTracker threadsafe
Original git commit by Alexander Larsson <alexl@redhat.com> at 1178716957 +0200 svn path=/trunk/; revision=538
Diffstat (limited to 'common/gmounttracker.c')
-rw-r--r--common/gmounttracker.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/common/gmounttracker.c b/common/gmounttracker.c
index 145e56c2..aa20ec8c 100644
--- a/common/gmounttracker.c
+++ b/common/gmounttracker.c
@@ -18,6 +18,7 @@ struct _GMountTracker
{
GObject parent_instance;
+ GMutex *lock;
GList *mounts;
};
@@ -111,6 +112,8 @@ g_mount_tracker_finalize (GObject *object)
tracker = G_MOUNT_TRACKER (object);
+ g_mutex_free (tracker->lock);
+
g_list_foreach (tracker->mounts,
(GFunc)g_mount_info_free, NULL);
g_list_free (tracker->mounts);
@@ -184,12 +187,16 @@ static void
g_mount_tracker_add_mount (GMountTracker *tracker,
GMountInfo *info)
{
+ g_mutex_lock (tracker->lock);
+
/* Don't add multiple times */
if (g_mount_tracker_find (tracker, info))
return;
tracker->mounts = g_list_prepend (tracker->mounts, g_mount_info_dup (info));
+ g_mutex_unlock (tracker->lock);
+
g_signal_emit (tracker, signals[MOUNTED], 0, info);
}
@@ -200,6 +207,8 @@ g_mount_tracker_remove_mount (GMountTracker *tracker,
GList *l;
GMountInfo *old_info;
+ g_mutex_lock (tracker->lock);
+
l = g_mount_tracker_find (tracker, info);
@@ -210,6 +219,8 @@ g_mount_tracker_remove_mount (GMountTracker *tracker,
old_info = l->data;
tracker->mounts = g_list_delete_link (tracker->mounts, l);
+
+ g_mutex_unlock (tracker->lock);
g_signal_emit (tracker, signals[UNMOUNTED], 0, old_info);
g_mount_info_free (old_info);
@@ -292,6 +303,8 @@ g_mount_tracker_init (GMountTracker *tracker)
DBusMessage *message;
DBusPendingCall *pending;
+ tracker->lock = g_mutex_new ();
+
conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
if (conn)
{
@@ -353,6 +366,8 @@ g_mount_tracker_list_mounts (GMountTracker *tracker)
GList *res, *l;
GMountInfo *copy;
+ g_mutex_lock (tracker->lock);
+
res = NULL;
for (l = tracker->mounts; l != NULL; l = l->next)
{
@@ -360,6 +375,8 @@ g_mount_tracker_list_mounts (GMountTracker *tracker)
res = g_list_prepend (res, copy);
}
+ g_mutex_unlock (tracker->lock);
+
return g_list_reverse (res);
}
@@ -368,17 +385,52 @@ g_mount_tracker_find_by_mount_spec (GMountTracker *tracker,
GMountSpec *mount_spec)
{
GList *l;
- GMountInfo *info;
+ GMountInfo *info, *found;
+
+ g_mutex_lock (tracker->lock);
+ found = NULL;
for (l = tracker->mounts; l != NULL; l = l->next)
{
info = l->data;
if (g_mount_spec_equal (info->mount_spec, mount_spec))
- return g_mount_info_dup (info);
+ {
+ found = g_mount_info_dup (info);
+ break;
+ }
}
- return NULL;
+ g_mutex_unlock (tracker->lock);
+
+ return found;
}
+gboolean
+g_mount_tracker_has_mount_spec (GMountTracker *tracker,
+ GMountSpec *mount_spec)
+{
+ GList *l;
+ GMountInfo *info;
+ gboolean found;
+
+ g_mutex_lock (tracker->lock);
+
+ found = FALSE;
+ for (l = tracker->mounts; l != NULL; l = l->next)
+ {
+ info = l->data;
+
+ if (g_mount_spec_equal (info->mount_spec, mount_spec))
+ {
+ found = TRUE;
+ break;
+ }
+ }
+
+ g_mutex_unlock (tracker->lock);
+
+ return found;
+}
+