diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2019-04-19 08:07:52 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2019-04-19 08:07:52 +0300 |
commit | fda44619ecb58be565ce60f64ea73627046c04f7 (patch) | |
tree | 0f4bda1236ea3d8b3d64c5d0ee80402ac3a49054 /win32_threads.c | |
parent | 74035e232e2f6ce86e95b4237fa256f0c83721fc (diff) | |
download | bdwgc-fda44619ecb58be565ce60f64ea73627046c04f7.tar.gz |
Remove Win32 main_thread static variable if threads discovery is disabled
(code refactoring)
* win32_threads.c (GC_main_thread): Do not define static variable if
GC_NO_THREADS_DISCOVERY.
* win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_attached_thread):
Reformat comment; move the definition to be near GC_please_stop.
* win32_threads.c [GC_NO_THREADS_DISCOVERY] (GC_thr_init): Define
GC_main_thread as a macro (and undefine it at the end of the function).
Diffstat (limited to 'win32_threads.c')
-rw-r--r-- | win32_threads.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/win32_threads.c b/win32_threads.c index f5a7209c..03cd04f0 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -166,8 +166,6 @@ GC_API void GC_CALL GC_use_threads_discovery(void) # endif } -STATIC DWORD GC_main_thread = 0; - #define ADDR_LIMIT ((ptr_t)GC_WORD_MAX) struct GC_Thread_Rep { @@ -260,23 +258,20 @@ typedef struct GC_Thread_Rep * GC_thread; typedef volatile struct GC_Thread_Rep * GC_vthread; #ifndef GC_NO_THREADS_DISCOVERY + STATIC DWORD GC_main_thread = 0; + + /* We track thread attachments while the world is supposed to be */ + /* stopped. Unfortunately, we cannot stop them from starting, since */ + /* blocking in DllMain seems to cause the world to deadlock. Thus, */ + /* we have to recover if we notice this in the middle of marking. */ + STATIC volatile AO_t GC_attached_thread = FALSE; + /* We assumed that volatile ==> memory ordering, at least among */ /* volatiles. This code should consistently use atomic_ops. */ STATIC volatile GC_bool GC_please_stop = FALSE; #elif defined(GC_ASSERTIONS) STATIC GC_bool GC_please_stop = FALSE; -#endif - -/* - * We track thread attachments while the world is supposed to be stopped. - * Unfortunately, we can't stop them from starting, since blocking in - * DllMain seems to cause the world to deadlock. Thus we have to recover - * If we notice this in the middle of marking. - */ - -#ifndef GC_NO_THREADS_DISCOVERY - STATIC volatile AO_t GC_attached_thread = FALSE; -#endif +#endif /* GC_NO_THREADS_DISCOVERY && GC_ASSERTIONS */ #if defined(WRAP_MARK_SOME) && !defined(GC_PTHREADS) /* Return TRUE if an thread was attached since we last asked or */ @@ -2490,7 +2485,11 @@ GC_INNER void GC_thr_init(void) if (GC_thr_initialized) return; GC_ASSERT((word)&GC_threads % sizeof(word) == 0); - GC_main_thread = GetCurrentThreadId(); +# ifdef GC_NO_THREADS_DISCOVERY +# define GC_main_thread GetCurrentThreadId() +# else + GC_main_thread = GetCurrentThreadId(); +# endif GC_thr_initialized = TRUE; # ifdef CAN_HANDLE_FORK @@ -2607,6 +2606,7 @@ GC_INNER void GC_thr_init(void) GC_ASSERT(0 == GC_lookup_thread_inner(GC_main_thread)); GC_register_my_thread_inner(&sb, GC_main_thread); +# undef GC_main_thread } #ifdef GC_PTHREADS |