summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2018-01-17 17:02:25 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2018-06-11 14:59:39 +0100
commit927de4433ef2c66c54bbf0ad9b7fa2c1c366b9ea (patch)
treeddfa6e39ca036210fc177661de0dd9fa06dccc6c
parente67e4cb8496e6ba66832319ab89d288219acdca5 (diff)
downloadglib-927de4433ef2c66c54bbf0ad9b7fa2c1c366b9ea.tar.gz
Port GHashTable to gatomicrefcount
Use the newly added API for reference counting instead of rolling our own.
-rw-r--r--glib/ghash.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/glib/ghash.c b/glib/ghash.c
index 87218114f..d93169066 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -37,7 +37,7 @@
#include "gatomic.h"
#include "gtestutils.h"
#include "gslice.h"
-
+#include "grefcount.h"
/**
* SECTION:hash_tables
@@ -227,7 +227,7 @@ struct _GHashTable
GHashFunc hash_func;
GEqualFunc key_equal_func;
- gint ref_count;
+ gatomicrefcount ref_count;
#ifndef G_DISABLE_ASSERT
/*
* Tracks the structure of the hash table, not its contents: is only
@@ -374,7 +374,7 @@ g_hash_table_lookup_node (GHashTable *hash_table,
* (as keys, etc. will be NULL).
* Applications need to either use g_hash_table_destroy, or ensure the hash
* table is empty prior to removing the last reference using g_hash_table_unref(). */
- g_assert (hash_table->ref_count > 0);
+ g_assert (!g_atomic_ref_count_compare (&hash_table->ref_count, 0));
hash_value = hash_table->hash_func (key);
if (G_UNLIKELY (!HASH_IS_REAL (hash_value)))
@@ -716,11 +716,11 @@ g_hash_table_new_full (GHashFunc hash_func,
hash_table = g_slice_new (GHashTable);
g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
+ g_atomic_ref_count_init (&hash_table->ref_count);
hash_table->nnodes = 0;
hash_table->noccupied = 0;
hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
hash_table->key_equal_func = key_equal_func;
- hash_table->ref_count = 1;
#ifndef G_DISABLE_ASSERT
hash_table->version = 0;
#endif
@@ -1077,7 +1077,7 @@ g_hash_table_ref (GHashTable *hash_table)
{
g_return_val_if_fail (hash_table != NULL, NULL);
- g_atomic_int_inc (&hash_table->ref_count);
+ g_atomic_ref_count_inc (&hash_table->ref_count);
return hash_table;
}
@@ -1098,7 +1098,7 @@ g_hash_table_unref (GHashTable *hash_table)
{
g_return_if_fail (hash_table != NULL);
- if (g_atomic_int_dec_and_test (&hash_table->ref_count))
+ if (g_atomic_ref_count_dec (&hash_table->ref_count))
{
g_hash_table_remove_all_nodes (hash_table, TRUE, TRUE);
if (hash_table->keys != hash_table->values)