diff options
author | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:56:22 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:56:22 +0000 |
commit | 97ec5fe812776c6d5089a331b5e03bdd2ffc028a (patch) | |
tree | 98834689a1c8c6a22ff51f61365c46c14de88d70 /common/gmountspec.c | |
parent | a3c2462fa5e4dbe4379b9221b41b30e89a465ee6 (diff) | |
download | gvfs-97ec5fe812776c6d5089a331b5e03bdd2ffc028a.tar.gz |
Add g_mount_spec_get_unique_for
Original git commit by Alexander Larsson <alexl@redhat.com> at 1188216947 +0200
svn path=/trunk/; revision=814
Diffstat (limited to 'common/gmountspec.c')
-rw-r--r-- | common/gmountspec.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/gmountspec.c b/common/gmountspec.c index 326b6403..7422f035 100644 --- a/common/gmountspec.c +++ b/common/gmountspec.c @@ -8,6 +8,9 @@ #include "gdbusutils.h" #include "gmountspec.h" +static GHashTable *unique_hash; +G_LOCK_DEFINE_STATIC(unique_hash); + static int item_compare (const void *_a, const void *_b) { @@ -33,6 +36,31 @@ g_mount_spec_new (const char *type) return spec; } +GMountSpec * +g_mount_spec_get_unique_for (GMountSpec *spec) +{ + GMountSpec *unique_spec; + + G_LOCK (unique_hash); + + if (unique_hash == NULL) + unique_hash = g_hash_table_new (g_mount_spec_hash, (GEqualFunc)g_mount_spec_equal); + + unique_spec = g_hash_table_lookup (unique_hash, spec); + + if (unique_spec == NULL) + { + g_hash_table_insert (unique_hash, spec, spec); + unique_spec = spec; + } + + g_mount_spec_ref (unique_spec); + + G_UNLOCK (unique_hash); + + return unique_spec; +} + void g_mount_spec_set_mount_prefix (GMountSpec *spec, const char *mount_prefix) @@ -126,6 +154,11 @@ g_mount_spec_unref (GMountSpec *spec) if (g_atomic_int_dec_and_test (&spec->ref_count)) { + G_LOCK (unique_hash); + if (unique_hash != NULL) + g_hash_table_remove (unique_hash, spec); + G_UNLOCK (unique_hash); + g_free (spec->mount_prefix); for (i = 0; i < spec->items->len; i++) { |