diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-05-25 08:41:37 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-05-25 09:54:42 +0300 |
commit | faa3bafd2da2d814b6ee1e99e38c44f3a54eed10 (patch) | |
tree | 9d9d8785e811314b1e0f25fb9d60604e24155aad /win32_threads.c | |
parent | 218e2571035ac6cea9633f713b5a4137bc8f3372 (diff) | |
download | bdwgc-faa3bafd2da2d814b6ee1e99e38c44f3a54eed10.tar.gz |
Ensure GC is initialized when GC_push_all_stacks() is called
(refactoring)
Also, remove an unnecessary lock in GC pthread_create (of
pthread_support.c), and ensure that GC_thr_init() is called only once.
* alloc.c (GC_try_to_collect_inner, GC_collect_a_little_inner,
GC_stopped_mark, GC_collect_or_expand, GC_allocobj): Add assertion that
GC is initialized.
* finalize.c (GC_register_disappearing_link_inner,
GC_register_finalizer_inner): Likewise.
* mark.c (GC_clear_marks, GC_initiate_gc): Likewise.
* mark_rts.c (GC_push_roots): Likewise.
* alloc.c (GC_collect_a_little): Call GC_init if GC is not initialized.
* alloc.c (GC_expand_hp): Move part of comment to gc.h.
* include/gc/gc.h (GC_expand_hp): Reformat comment.
* darwin_stop_world.c (GC_push_all_stacks): Replace GC_init() call with
the assertion that GC_thr_initialized.
* pthread_stop_world.c (GC_push_all_stacks): Likewise.
* pthread_support.c (pthread_create): Likewise.
* darwin_stop_world.c (GC_stop_world): Add assertion that
GC_thr_initialized.
* pthread_stop_world.c (GC_stop_world): Likewise.
* win32_threads.c (GC_push_all_stacks): Likewise.
* finalize.c (GC_register_finalizer_inner): Add assertion (after LOCK)
that obj points to the base address of the object.
* include/private/pthread_support.h (GC_thr_initialized): Declare only
if GC_ASSERTIONS.
* pthread_support.c (GC_thr_initialized): Define only if GC_ASSERTIONS.
* win32_threads.c (GC_thr_initialized): Likewise.
* pthread_support.c (GC_thr_init): Add assertion that
GC_thr_initialized is not set on entry; set GC_thr_initialized only
if GC_ASSERTIONS.
* win32_threads.c (GC_thr_init): Likewise.
* pthread_support.c (pthread_create): Remove LOCK/UNLOCK around setup
of si.
* win32_threads.c (GC_stop_world): Replace ABORT (about
GC_thr_initialized) with the assertion.
* win32_threads.c (GC_CreateThread): Add assertion that
GC_thr_initialized after GC_init_parallel() call.
* win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT]
(GC_beginthreadex): Likewise.
* win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise.
* win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT]
(GC_beginthreadex): Remove comment duplicating that in GC_CreateThread.
* win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise.
Diffstat (limited to 'win32_threads.c')
-rw-r--r-- | win32_threads.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/win32_threads.c b/win32_threads.c index f41bf46b..972b02c1 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -153,7 +153,9 @@ static ptr_t copy_ptr_regs(word *regs, const CONTEXT *pcontext); /* this better. */ typedef LONG * IE_t; -STATIC GC_bool GC_thr_initialized = FALSE; +#ifdef GC_ASSERTIONS + STATIC GC_bool GC_thr_initialized = FALSE; +#endif #ifndef GC_ALWAYS_MULTITHREADED GC_INNER GC_bool GC_need_to_lock = FALSE; @@ -1366,9 +1368,8 @@ GC_INNER void GC_stop_world(void) { DWORD thread_id = GetCurrentThreadId(); - if (!GC_thr_initialized) - ABORT("GC_stop_world() called before GC_thr_init()"); GC_ASSERT(I_HOLD_LOCK()); + GC_ASSERT(GC_thr_initialized); /* This code is the same as in pthread_stop_world.c */ # ifdef PARALLEL_MARK @@ -1815,6 +1816,7 @@ GC_INNER void GC_push_all_stacks(void) word total_size = 0; GC_ASSERT(I_HOLD_LOCK()); + GC_ASSERT(GC_thr_initialized); # ifndef GC_NO_THREADS_DISCOVERY if (GC_win32_dll_threads) { int i; @@ -2572,8 +2574,9 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, { if (!EXPECT(parallel_initialized, TRUE)) GC_init_parallel(); - /* make sure GC is initialized (i.e. main thread is */ - /* attached, tls initialized). */ + GC_ASSERT(GC_thr_initialized); + /* Make sure GC is initialized (i.e. main thread is */ + /* attached, tls is initialized). */ # ifdef DEBUG_THREADS GC_log_printf("About to create a thread from 0x%lx\n", @@ -2623,8 +2626,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, { if (!EXPECT(parallel_initialized, TRUE)) GC_init_parallel(); - /* make sure GC is initialized (i.e. main thread is */ - /* attached, tls initialized). */ + GC_ASSERT(GC_thr_initialized); # ifdef DEBUG_THREADS GC_log_printf("About to create a thread from 0x%lx\n", (long)GetCurrentThreadId()); @@ -2765,15 +2767,16 @@ GC_INNER void GC_thr_init(void) # endif GC_ASSERT(I_HOLD_LOCK()); - if (GC_thr_initialized) return; - + GC_ASSERT(!GC_thr_initialized); GC_ASSERT((word)&GC_threads % sizeof(word) == 0); +# ifdef GC_ASSERTIONS + GC_thr_initialized = TRUE; +# endif # ifdef GC_NO_THREADS_DISCOVERY # define GC_main_thread GetCurrentThreadId() # else GC_main_thread = GetCurrentThreadId(); # endif - GC_thr_initialized = TRUE; # ifdef CAN_HANDLE_FORK /* Prepare for forks if requested. */ @@ -2966,7 +2969,7 @@ GC_INNER void GC_thr_init(void) if (!EXPECT(parallel_initialized, TRUE)) GC_init_parallel(); - /* make sure GC is initialized (i.e. main thread is attached) */ + GC_ASSERT(GC_thr_initialized); GC_ASSERT(!GC_win32_dll_threads); /* This is otherwise saved only in an area mmapped by the thread */ |