From: Armin Hasitzka Date: Wed, 20 Sep 2017 20:01:03 +0000 (+0200) Subject: Mark `mono_g_hash_table_max_chain_length` as known and accepted data race (#5520) X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=5b483a682096189eddd25d856358726f007fdbcf Mark `mono_g_hash_table_max_chain_length` as known and accepted data race (#5520) [TSan] Unlock mono_g_hash_table_max_chain_length I would suggest using `Unlocked* ()` here. `mono_g_hash_table_find_slot ()` is called relatively often and, unlike increment or add operations, read and write operations (without a global surrounding lock) do not gain much (if anything) by being interlocked as long as they can be read and written by one instruction. That should be true for 32-bit integers and Mono's supported platforms. --- diff --git a/mono/metadata/mono-hash.c b/mono/metadata/mono-hash.c index 1b558370d02..4ef79e7385c 100644 --- a/mono/metadata/mono-hash.c +++ b/mono/metadata/mono-hash.c @@ -34,8 +34,9 @@ #include "metadata/gc-internals.h" #include #include +#include -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))) @@ -136,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; } diff --git a/mono/metadata/mono-hash.h b/mono/metadata/mono-hash.h index 7f778e50bd1..10e3ca390ed 100644 --- a/mono/metadata/mono-hash.h +++ b/mono/metadata/mono-hash.h @@ -22,7 +22,7 @@ typedef enum { MONO_HASH_KEY_VALUE_GC = MONO_HASH_KEY_GC | MONO_HASH_VALUE_GC, } MonoGHashGCType; -extern int mono_g_hash_table_max_chain_length; +extern gint32 mono_g_hash_table_max_chain_length; typedef struct _MonoGHashTable MonoGHashTable;