Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / mono-hash.c
index 9c6cdb44101c6479dfbc36381aefc2252a7fb074..4ef79e7385c5d70efaeddd8d5aa7109d53675382 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * ghashtable.c: Hashtable implementation
+/**
+ * \file
+ * Hashtable implementation
  *
  * Author:
  *   Miguel de Icaza (miguel@novell.com)
@@ -33,8 +34,9 @@
 #include "metadata/gc-internals.h"
 #include <mono/utils/checked-build.h>
 #include <mono/utils/mono-threads-coop.h>
+#include <mono/utils/unlocked.h>
 
-int mono_g_hash_table_max_chain_length;
+gint32 mono_g_hash_table_max_chain_length;
 
 #ifdef HAVE_BOEHM_GC
 #define mg_new0(type,n)  ((type *) GC_MALLOC(sizeof(type) * (n)))
@@ -135,10 +137,12 @@ static inline int mono_g_hash_table_find_slot (MonoGHashTable *hash, const MonoO
                }
        }
 
-       if (i > start && (i - start) > mono_g_hash_table_max_chain_length)
-               mono_g_hash_table_max_chain_length = i - start;
-       else if (i < start && (hash->table_size - (start - i)) > mono_g_hash_table_max_chain_length)
-               mono_g_hash_table_max_chain_length = hash->table_size - (start - i);
+       gint32 max_length = UnlockedRead (&mono_g_hash_table_max_chain_length);
+       if (i > start && (i - start) > max_length)
+               UnlockedWrite (&mono_g_hash_table_max_chain_length, i - start);
+       else if (i < start && (hash->table_size - (start - i)) > max_length)
+               UnlockedWrite (&mono_g_hash_table_max_chain_length, hash->table_size - (start - i));
+
        return i;
 }
 
@@ -256,6 +260,9 @@ rehash (MonoGHashTable *hash)
        mg_free (old_values);
 }
 
+/**
+ * mono_g_hash_table_size:
+ */
 guint
 mono_g_hash_table_size (MonoGHashTable *hash)
 {
@@ -264,6 +271,9 @@ mono_g_hash_table_size (MonoGHashTable *hash)
        return hash->in_use;
 }
 
+/**
+ * mono_g_hash_table_lookup:
+ */
 gpointer
 mono_g_hash_table_lookup (MonoGHashTable *hash, gconstpointer key)
 {
@@ -275,6 +285,9 @@ mono_g_hash_table_lookup (MonoGHashTable *hash, gconstpointer key)
                return NULL;
 }
 
+/**
+ * mono_g_hash_table_lookup_extended:
+ */
 gboolean
 mono_g_hash_table_lookup_extended (MonoGHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value)
 {
@@ -293,6 +306,9 @@ mono_g_hash_table_lookup_extended (MonoGHashTable *hash, gconstpointer key, gpoi
        return FALSE;
 }
 
+/**
+ * mono_g_hash_table_foreach:
+ */
 void
 mono_g_hash_table_foreach (MonoGHashTable *hash, GHFunc func, gpointer user_data)
 {
@@ -322,6 +338,9 @@ mono_g_hash_table_find (MonoGHashTable *hash, GHRFunc predicate, gpointer user_d
        return NULL;
 }
 
+/**
+ * mono_g_hash_table_remove:
+ */
 gboolean
 mono_g_hash_table_remove (MonoGHashTable *hash, gconstpointer key)
 {
@@ -374,6 +393,9 @@ mono_g_hash_table_remove (MonoGHashTable *hash, gconstpointer key)
        return TRUE;
 }
 
+/**
+ * mono_g_hash_table_foreach_remove:
+ */
 guint
 mono_g_hash_table_foreach_remove (MonoGHashTable *hash, GHRFunc func, gpointer user_data)
 {
@@ -396,6 +418,9 @@ mono_g_hash_table_foreach_remove (MonoGHashTable *hash, GHRFunc func, gpointer u
        return count;
 }
 
+/**
+ * mono_g_hash_table_destroy:
+ */
 void
 mono_g_hash_table_destroy (MonoGHashTable *hash)
 {
@@ -454,12 +479,18 @@ mono_g_hash_table_insert_replace (MonoGHashTable *hash, gpointer key, gpointer v
        }
 }
 
+/**
+ * mono_g_hash_table_insert:
+ */
 void
 mono_g_hash_table_insert (MonoGHashTable *h, gpointer k, gpointer v)
 {
        mono_g_hash_table_insert_replace (h, k, v, FALSE);
 }
 
+/**
+ * mono_g_hash_table_replace:
+ */
 void
 mono_g_hash_table_replace(MonoGHashTable *h, gpointer k, gpointer v)
 {