Skip to content

Commit

Permalink
Merge pull request mono#5299 from cherusker/cherusker-2017-08-01-next…
Browse files Browse the repository at this point in the history
…-generic-inst-id

[metadata] Fix racy next_generic_inst_id

Like suggested by @luhenry, I would like to propose this fix which was discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423. As `next_generic_inst_id` is `int`, `InterlockedIncrement64 ()` seems to be the right choice.

Also, I cannot add any reviewers or assignees, which is why I would kindly ask @lambdageek to review this as well :)
  • Loading branch information
monojenkins authored Aug 2, 2017
2 parents 266c991 + 47535f5 commit 8bbca2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ struct MonoVTable {
*/
struct _MonoGenericInst {
#ifndef MONO_SMALL_CONFIG
guint id; /* unique ID for debugging */
gint32 id; /* unique ID for debugging */
#endif
guint type_argc : 22; /* number of type arguments */
guint is_open : 1; /* if this is an open type */
Expand Down
4 changes: 2 additions & 2 deletions mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ builtin_types[] = {
#define NBUILTIN_TYPES() (sizeof (builtin_types) / sizeof (builtin_types [0]))

static GHashTable *type_cache = NULL;
static int next_generic_inst_id = 0;
static gint32 next_generic_inst_id = 0;

/* Protected by image_sets_mutex */
static MonoImageSet *mscorlib_image_set;
Expand Down Expand Up @@ -3160,7 +3160,7 @@ mono_metadata_get_canonical_generic_inst (MonoGenericInst *candidate)
int size = MONO_SIZEOF_GENERIC_INST + type_argc * sizeof (MonoType *);
ginst = (MonoGenericInst *)mono_image_set_alloc0 (set, size);
#ifndef MONO_SMALL_CONFIG
ginst->id = ++next_generic_inst_id;
ginst->id = InterlockedIncrement (&next_generic_inst_id);
#endif
ginst->is_open = is_open;
ginst->type_argc = type_argc;
Expand Down

0 comments on commit 8bbca2b

Please sign in to comment.