diff options
-rw-r--r-- | common/gmounttracker.c | 58 | ||||
-rw-r--r-- | common/gmounttracker.h | 2 |
2 files changed, 57 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; +} + diff --git a/common/gmounttracker.h b/common/gmounttracker.h index 2a717a1f..58696395 100644 --- a/common/gmounttracker.h +++ b/common/gmounttracker.h @@ -45,6 +45,8 @@ GMountTracker *g_mount_tracker_new (void); GList * g_mount_tracker_list_mounts (GMountTracker *tracker); GMountInfo * g_mount_tracker_find_by_mount_spec (GMountTracker *tracker, GMountSpec *mount_spec); +gboolean g_mount_tracker_has_mount_spec (GMountTracker *tracker, + GMountSpec *mount_spec); G_END_DECLS |