Fix on-demand initialization race conditions [sre.c]. (mono/mono#18164)
authorJay Krell <jaykrell@microsoft.com>
Thu, 12 Dec 2019 22:55:33 +0000 (14:55 -0800)
committermonojenkins <jo.shields+jenkins@xamarin.com>
Thu, 12 Dec 2019 22:55:33 +0000 (23:55 +0100)
Fix on-demand initialization race conditions [sre.c].

Extracted from https://github.com/mono/mono/pull/18150 which reviewer said was too big.

Commit migrated from https://github.com/mono/mono/commit/620d7cf84d026417c0390bcef0b50acda6e0f40d

src/mono/mono/metadata/sre.c

index be32563..2fe2fac 100644 (file)
@@ -1650,15 +1650,16 @@ mono_is_sre_ctor_on_tb_inst (MonoClass *klass)
 static MonoReflectionTypeHandle
 mono_reflection_type_get_underlying_system_type (MonoReflectionTypeHandle t, MonoError *error)
 {
-       static MonoMethod *method_get_underlying_system_type = NULL;
        HANDLE_FUNCTION_ENTER ();
 
        error_init (error);
 
-       if (!method_get_underlying_system_type) {
+       MONO_STATIC_POINTER_INIT (MonoMethod, method_get_underlying_system_type)
+
                method_get_underlying_system_type = mono_class_get_method_from_name_checked (mono_defaults.systemtype_class, "get_UnderlyingSystemType", 0, 0, error);
                mono_error_assert_ok (error);
-       }
+
+       MONO_STATIC_POINTER_INIT_END (MonoMethod, method_get_underlying_system_type)
 
        MonoReflectionTypeHandle rt = MONO_HANDLE_NEW (MonoReflectionType, NULL);