Skip to content

Commit

Permalink
Mark mono_g_hash_table_max_chain_length as known and accepted data …
Browse files Browse the repository at this point in the history
…race (mono/mono#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.


Commit migrated from mono/mono@5b483a6
  • Loading branch information
cherusker authored and monojenkins committed Sep 20, 2017
1 parent 532448c commit c87d4c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/mono/mono/metadata/mono-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,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)))
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/mono-hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c87d4c6

Please sign in to comment.