Merge pull request #2438 from lambdageek/cherry-pick-coop-handle
[mono.git] / mono / utils / checked-build.c
index 65bff4d26fba514ac65af3529cc1042adb631e43..eedb554789203998a8c9680618106473994a3789 100644 (file)
@@ -81,7 +81,7 @@ translate_backtrace (gpointer native_trace[], int size)
 
 typedef struct {
        GPtrArray *transitions;
-       gboolean in_gc_critical_region;
+       guint32 in_gc_critical_region;
 } CheckState;
 
 typedef struct {
@@ -235,7 +235,7 @@ void *
 critical_gc_region_begin(void)
 {
        CheckState *state = get_state ();
-       state->in_gc_critical_region = TRUE;
+       state->in_gc_critical_region++;
        return state;
 }
 
@@ -245,20 +245,26 @@ critical_gc_region_end(void* token)
 {
        CheckState *state = get_state();
        g_assert (state == token);
-       state->in_gc_critical_region = FALSE;
+       state->in_gc_critical_region--;
 }
 
 void
 assert_not_in_gc_critical_region(void)
 {
        CheckState *state = get_state();
-       if (state->in_gc_critical_region) {
-               MonoThreadInfo *cur = mono_thread_info_current();
-               state = mono_thread_info_current_state(cur);
-               assertion_fail("Expected GC Unsafe mode, but was in %s state", mono_thread_state_name(state));
+       if (state->in_gc_critical_region > 0) {
+               assertion_fail("Expected GC Unsafe mode, but was in %s state", mono_thread_state_name (mono_thread_info_current_state (mono_thread_info_current ())));
        }
 }
 
+void
+assert_in_gc_critical_region (void)
+{
+       CheckState *state = get_state();
+       if (state->in_gc_critical_region == 0)
+               assertion_fail("Expected GC critical region");
+}
+
 // check_metadata_store et al: The goal of these functions is to verify that if there is a pointer from one mempool into
 // another, that the pointed-to memory is protected by the reference count mechanism for MonoImages.
 //