Fix racy `next_generic_inst_id`
authorcherusker <prince.cherusker@gmail.com>
Tue, 1 Aug 2017 10:59:34 +0000 (12:59 +0200)
committercherusker <prince.cherusker@gmail.com>
Wed, 2 Aug 2017 19:17:43 +0000 (21:17 +0200)
- as discussed in https://bugzilla.xamarin.com/show_bug.cgi?id=58423
- in addition, unify `int` and `guint` into `gint32` which can be used flawlessly with `InterlockedIncrement ()`

mono/metadata/class-internals.h
mono/metadata/metadata.c

index 39061bd142a1ec1e5411aaee98f7848babe99d1b..ef8127e14a4ab94e43f545d5eea84ef80f660039 100644 (file)
@@ -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 */
index 651538c3c5cb3378ccdd2bef5423c4a81d73b49d..aea1343df99c5dac29b3945222b080ea19b6b481 100644 (file)
@@ -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;
@@ -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;