Mark operations on `shutting_down` as known and accepted data races
authorcherusker <prince.cherusker@gmail.com>
Thu, 7 Sep 2017 09:25:09 +0000 (11:25 +0200)
committermonojenkins <jo.shields+jenkins@xamarin.com>
Tue, 12 Sep 2017 17:25:31 +0000 (19:25 +0200)
mono/metadata/runtime.c
mono/utils/unlocked.h

index cd0c0e6123a81ab07a0ee56a2d4aabdf654b25c3..226983cef696d42657e2dde5dd87a62418814243 100644 (file)
@@ -3,7 +3,7 @@
  * Runtime functions
  *
  * Authors:
- *  Jonathan Pryor 
+ *  Jonathan Pryor
  *
  * Copyright 2010 Novell, Inc (http://www.novell.com)
  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 #include <mono/metadata/threadpool.h>
 #include <mono/metadata/marshal.h>
 #include <mono/utils/atomic.h>
+#include <mono/utils/unlocked.h>
 
 static gboolean shutting_down_inited = FALSE;
 static gboolean shutting_down = FALSE;
 
-/** 
+/**
  * mono_runtime_set_shutting_down:
  * \deprecated This function can break the shutdown sequence.
  *
@@ -36,7 +37,7 @@ static gboolean shutting_down = FALSE;
 void
 mono_runtime_set_shutting_down (void)
 {
-       shutting_down = TRUE;
+       UnlockedWriteBool (&shutting_down, TRUE);
 }
 
 /**
@@ -47,7 +48,7 @@ mono_runtime_set_shutting_down (void)
 gboolean
 mono_runtime_is_shutting_down (void)
 {
-       return shutting_down;
+       return UnlockedReadBool (&shutting_down);
 }
 
 static void
@@ -61,7 +62,7 @@ fire_process_exit_event (MonoDomain *domain, gpointer user_data)
        field = mono_class_get_field_from_name (mono_defaults.appdomain_class, "ProcessExit");
        g_assert (field);
 
-       delegate = *(MonoObject **)(((char *)domain->domain) + field->offset); 
+       delegate = *(MonoObject **)(((char *)domain->domain) + field->offset);
        if (delegate == NULL)
                return;
 
@@ -79,7 +80,6 @@ mono_runtime_fire_process_exit_event (void)
 #endif
 }
 
-
 /**
  * mono_runtime_try_shutdown:
  *
@@ -97,14 +97,12 @@ mono_runtime_try_shutdown (void)
 
        mono_runtime_fire_process_exit_event ();
 
-       shutting_down = TRUE;
+       mono_runtime_set_shutting_down ();
 
        mono_threads_set_shutting_down ();
 
        /* No new threads will be created after this point */
 
-       mono_runtime_set_shutting_down ();
-
        /*TODO move the follow to here:
        mono_thread_suspend_all_other_threads (); OR  mono_thread_wait_all_other_threads
 
index 07622dde6572ceac721739fa41d8677367ee4e3c..dedcc4e73cf066ad777e8bc0510f978b65c619a4 100644 (file)
@@ -94,6 +94,13 @@ UnlockedWrite64 (gint64 *dest, gint64 val)
        *dest = val;
 }
 
+MONO_UNLOCKED_ATTRS
+void
+UnlockedWriteBool (gboolean *dest, gboolean val)
+{
+       *dest = val;
+}
+
 MONO_UNLOCKED_ATTRS
 gint32
 UnlockedRead (gint32 *src)
@@ -108,4 +115,11 @@ UnlockedRead64 (gint64 *src)
        return *src;
 }
 
+MONO_UNLOCKED_ATTRS
+gboolean
+UnlockedReadBool (gboolean *src)
+{
+       return *src;
+}
+
 #endif /* _UNLOCKED_H_ */