From dabce82fc68eadae5f5de87dacf52eb0509c3361 Mon Sep 17 00:00:00 2001 From: ivmai Date: Fri, 6 Nov 2009 05:54:29 +0000 Subject: [PATCH] 2009-11-06 Ivan Maidanski * include/private/gc_priv.h (GC_write_disabled): New variable declaration (only if GC_ASSERTIONS and Win32 threads). * misc.c (GC_write): Add assertion for GC_write_disabled value is not on (only if THREADS). * win32_threads.c (GC_write_disabled): New variable (only if GC_ASSERTIONS and not Cygwin). * win32_threads.c (GC_stop_world): Set and clear GC_write_disabled (while holding GC_write_cs). --- ChangeLog | 13 ++++++++++++- include/private/gc_priv.h | 8 +++++++- misc.c | 3 +++ win32_threads.c | 12 ++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b64fe99..dcc0f05b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-11-06 Ivan Maidanski + + * include/private/gc_priv.h (GC_write_disabled): New variable + declaration (only if GC_ASSERTIONS and Win32 threads). + * misc.c (GC_write): Add assertion for GC_write_disabled value is + not on (only if THREADS). + * win32_threads.c (GC_write_disabled): New variable (only if + GC_ASSERTIONS and not Cygwin). + * win32_threads.c (GC_stop_world): Set and clear GC_write_disabled + (while holding GC_write_cs). + 2009-11-05 Ivan Maidanski * win32_threads.c (GC_please_stop): If DllMain-based thread @@ -7,7 +18,7 @@ * win32_threads.c (GC_stop_world): Add the comment for GC_printf() usage (while holding GC_write_cs). * win32_threads.c (GC_delete_gc_thread): Ditto. - * os_depc.c (GC_remove_protection): Ditto. + * os_dep.c (GC_remove_protection): Ditto. 2009-11-05 Ivan Maidanski diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 49041a9a..000661fa 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -2011,6 +2011,12 @@ GC_EXTERN signed_word GC_bytes_found; #ifdef THREADS # if defined(MSWIN32) || defined(MSWINCE) GC_EXTERN CRITICAL_SECTION GC_write_cs; /* defined in misc.c */ +# ifdef GC_ASSERTIONS + GC_EXTERN GC_bool GC_write_disabled; + /* defined in win32_threads.c; */ + /* protected by GC_write_cs. */ + +# endif # endif # ifdef MPROTECT_VDB GC_EXTERN volatile AO_TS_t GC_fault_handler_lock; @@ -2018,7 +2024,7 @@ GC_EXTERN signed_word GC_bytes_found; # endif # ifdef MSWINCE GC_EXTERN GC_bool GC_dont_query_stack_min; - /* Defined and set in os_dep.c. */ + /* Defined and set in os_dep.c. */ # endif #elif defined(IA64) GC_EXTERN ptr_t GC_save_regs_ret_val; /* defined in mach_dep.c. */ diff --git a/misc.c b/misc.c index f7a10a6f..4254096e 100644 --- a/misc.c +++ b/misc.c @@ -978,6 +978,9 @@ out: if (len == 0) return 0; IF_NEED_TO_LOCK(EnterCriticalSection(&GC_write_cs)); +# ifdef THREADS + GC_ASSERT(!GC_write_disabled); +# endif if (GC_stdout == INVALID_HANDLE_VALUE) { IF_NEED_TO_LOCK(LeaveCriticalSection(&GC_write_cs)); return -1; diff --git a/win32_threads.c b/win32_threads.c index 04601dec..393cedb4 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -966,6 +966,11 @@ STATIC void GC_suspend(GC_thread t) # endif } +#if defined(GC_ASSERTIONS) && !defined(CYGWIN32) + GC_INNER GC_bool GC_write_disabled = FALSE; + /* TRUE only if GC_stop_world() acquired GC_write_cs. */ +#endif + GC_INNER void GC_stop_world(void) { DWORD thread_id = GetCurrentThreadId(); @@ -987,12 +992,16 @@ GC_INNER void GC_stop_world(void) GC_please_stop = TRUE; # endif # ifndef CYGWIN32 + GC_ASSERT(!GC_write_disabled); EnterCriticalSection(&GC_write_cs); /* It's not allowed to call GC_printf() (and friends) here down to */ /* LeaveCriticalSection (same applies recursively to */ /* GC_get_max_thread_index(), GC_suspend(), GC_delete_gc_thread() */ /* (only if GC_win32_dll_threads), GC_size() and */ /* GC_remove_protection()). */ +# ifdef GC_ASSERTIONS + GC_write_disabled = TRUE; +# endif # endif # ifndef GC_NO_DLLMAIN if (GC_win32_dll_threads) { @@ -1026,6 +1035,9 @@ GC_INNER void GC_stop_world(void) } } # ifndef CYGWIN32 +# ifdef GC_ASSERTIONS + GC_write_disabled = FALSE; +# endif LeaveCriticalSection(&GC_write_cs); # endif # ifdef PARALLEL_MARK -- 2.40.0