From: Jay Krell Date: Fri, 13 Dec 2019 03:55:58 +0000 (-0800) Subject: Fix on-demand initialization race conditions [sgen]. (mono/mono#18170) X-Git-Tag: submit/tizen/20210909.063632~10331^2~5^2~89 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65b5d9df522b7464a26927f87b6e99a3a7ae212a;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix on-demand initialization race conditions [sgen]. (mono/mono#18170) Fix on-demand initialization race conditions [sgen]. Extracted from https://github.com/mono/mono/pull/18150 which reviewer said was too big. Commit migrated from https://github.com/mono/mono/commit/9cefdf59adc59b085ff8cf187fabb17aa9a40737 --- diff --git a/src/mono/mono/metadata/sgen-toggleref.c b/src/mono/mono/metadata/sgen-toggleref.c index 3fa53bd..831d0aa 100644 --- a/src/mono/mono/metadata/sgen-toggleref.c +++ b/src/mono/mono/metadata/sgen-toggleref.c @@ -213,13 +213,14 @@ mono_gc_toggleref_register_callback (MonoToggleRefStatus (*proccess_toggleref) ( static MonoToggleRefStatus test_toggleref_callback (MonoObject *obj) { - static MonoClassField *mono_toggleref_test_field; MonoToggleRefStatus status = MONO_TOGGLE_REF_DROP; - if (!mono_toggleref_test_field) { + MONO_STATIC_POINTER_INIT (MonoClassField, mono_toggleref_test_field) + mono_toggleref_test_field = mono_class_get_field_from_name_full (mono_object_class (obj), "__test", NULL); g_assert (mono_toggleref_test_field); - } + + MONO_STATIC_POINTER_INIT_END (MonoClassField, mono_toggleref_test_field) /* In coop mode, important to not call a helper that will pin obj! */ mono_field_get_value_internal (obj, mono_toggleref_test_field, &status);