summaryrefslogtreecommitdiff
path: root/win32_threads.c
Commit message (Collapse)AuthorAgeFilesLines
* Use EXPECT() in GC_lookup_thread and GC_lookup_by_pthreadIvan Maidanski2023-04-061-1/+1
| | | | | | | | | (refactoring) * pthread_support.c (GC_lookup_thread): Expect break on the first iteration of the loop. * win32_threads.c [GC_PTHREADS] (GC_lookup_by_pthread): Expect return on the first iteration of the first loop.
* Add assertion to verify GC_threads hash table entries are chained properlyIvan Maidanski2023-04-061-1/+3
| | | | | | | | | (refactoring) * darwin_stop_world.c (GC_push_all_stacks): Add assertion that thread entry is located in the proper hash table chain (by id). * pthread_stop_world.c (GC_push_all_stacks): Likewise. * win32_threads.c (GC_push_all_stacks): Likewise.
* Fix signals delivery fail in find-leak mode if init from non-main threadIvan Maidanski2023-04-061-8/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #542 (bdwgc). The scenario of the failure (on Linux): - Find-leak mode is on - pthread_create/join primitives are not redirected - GC is initialized from a thread other than primordial - that thread is terminated (but not unregistered as the 1st one in GC) - the primordial thread exits and launches GC_exit_check - GC_gcollect tries to suspend the terminated thread by sending a signal - the signal is not delivered but pthread_kill just returns zero - the signal sending is retried until aborting with the proper message. The proposed solution (workaround) is not to call GC_gcollect at the process exit (in the find-leak mode) if GC_init was called from a thread other than primordial one. Check in GC_exit_check() (which is called if GC_find_leak) that the thread executing at-exit functions is the same as the one performed the GC initialization, otherwise the latter thread might already be dead but still registered and this, as a consequence, might cause a signal delivery fail when suspending the threads on platforms that do not guarantee ESRCH returned if the signal is not delivered (as observed on Ubuntu 22). * include/private/gc_priv.h [THREADS && !DONT_USE_ATEXIT] (GC_is_main_thread): Declare GC_INNER function. * include/private/pthread_support.h [GC_WIN32_THREADS && !DONT_USE_ATEXIT] (GC_main_thread_id): Declare variable. * include/private/pthread_support.h [GC_WIN32_THREADS && !GC_NO_THREADS_DISCOVERY] (GC_main_thread_id): Do not depend on GC_ASSERTIONS. * misc.c [!DONT_USE_ATEXIT && THREADS] (GC_exit_check): If not GC_is_main_thread() or not GC_thread_is_registered() then do not call GC_gcollect(); add comment; do not set and clear GC_in_thread_creation. * pthread_support.c [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS || !DONT_USE_ATEXIT] (GC_main_thread_id): Define variable. * pthread_support.c [!DONT_USE_ATEXIT] (GC_is_main_thread): Implement. * pthread_support.c [!GC_WIN32_THREADS] (GC_thr_init): Define self_id local variable. * pthread_support.c [!GC_WIN32_THREADS && !DONT_USE_ATEXIT] (GC_thr_init): Set GC_main_thread_id. * win32_threads.c [!DONT_USE_ATEXIT] (GC_thr_init): Likewise. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_main_thread_id): Do not define variable.
* Define GC_self_thread_inner to lookup GC_thread of current threadIvan Maidanski2023-03-041-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * include/private/pthread_support.h (GC_self_thread_inner): New macro. * pthread_stop_world.c (GC_lookup_thread_async): Replace to no-arg GC_lookup_self_thread_async(); update comment. * pthread_stop_world.c (GC_suspend_handler_inner): Remove self local variable, use pthread_self() instead. * pthread_stop_world.c [NACL] (__nacl_suspend_thread_if_needed): Likewise. * pthread_stop_world.c (GC_suspend_handler_inner): Call GC_lookup_self_thread_async() instead of GC_lookup_thread_async(self). * pthread_stop_world.c [NACL] (GC_nacl_shutdown_gc_thread): Do not use GC_lookup_thread(pthread_self()) in assertion. * win32_threads.c (GC_thr_init): Likewise. * pthread_support.c (GC_self_thread): New STATIC function. * pthread_support.c [!GC_NO_FINALIZATION] (GC_reset_finalizer_nested): Remove me local variable. * pthread_support.c [!GC_NO_FINALIZATION] (GC_reset_finalizer_nested, GC_check_finalizer_nested): Call GC_self_thread_inner() instead of GC_lookup_thread(thread_id_self()). * pthread_support.c [!GC_WIN32_THREADS] (GC_register_altstack, GC_thr_init): Likewise. * pthread_support.c [THREAD_LOCAL_ALLOC] (GC_init_parallel): Likewise. * pthread_support.c (GC_do_blocking_inner, GC_set_stackbottom, GC_get_stackbottom, GC_call_with_gc_active, GC_unregister_my_thread, GC_register_my_thread): Likewise. * pthread_support.c [GC_HAVE_PTHREAD_EXIT] (GC_pthread_exit): Likewise. * pthread_support.c [GC_ASSERTIONS && THREAD_LOCAL_ALLOC] (GC_is_thread_tsd_valid): Use GC_self_thread() instead of locking and GC_lookup_thread(thread_id_self()). * pthread_support.c (GC_thread_is_registered): Likewise. * pthread_support.c [GC_ASSERTIONS] (GC_allow_register_threads): Likewise. * pthread_support.c (GC_thread_is_registered, GC_get_stackbottom, GC_call_with_gc_active, GC_unregister_my_thread, GC_register_my_thread): Remove self_id local variable. * pthread_support.c [!GC_WIN32_THREADS] (GC_register_altstack, GC_thr_init): Likewise. * pthread_support.c [GC_HAVE_PTHREAD_EXIT] (GC_pthread_exit): Likewise.
* Adjust WoW64 workaround to work on UWP/WinRTJonathan Chambers2023-02-201-17/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (cherry-pick of c511d4a from Unity-Technologies/bdwgc) Dynamically lookup IsWow64Process2 and fallback to IsWow64Process if needed. Store TIB on each thread and lookup via call to NtCurrentTeb on thread registration rather than calling GetThreadSelectorEntry which is not available on UWP. * include/private/pthread_support.h [WOW64_THREAD_CONTEXT_WORKAROUND && MSWINRT_FLAVOR] (GC_thread): Add tib field. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND && MSWINRT_FLAVOR] (GC_register_my_thread_inner): Call NtCurrentTeb() and set tib field; add comment. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (isWow64): Change type from BOOL to GC_bool. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_push_stack_for): Define SegFs and selector local variables only unless MSWINRT_FLAVOR; do not call GetThreadSelectorEntry() if MSWINRT_FLAVOR. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND && MSWINRT_FLAVOR] (GetModuleHandleW): Declare. * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (is_wow64_process): New static function (move part of code from GC_thr_init). * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND && MSWINRT_FLAVOR] (is_wow64_process): Call IsWow64Process2() dynamically; call IsWow64Process() statically (if the previous one failed). * win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND] (GC_thr_init): Call is_wow64_process(). Co-authored-by: Ivan Maidanski <ivmai@mail.ru>
* Uniform use of GC_lookup_by_pthread in GC_pthread_join/detachIvan Maidanski2022-12-311-18/+13
| | | | | | | | | | | | | | | | | | | | | | | (refactoring) * include/private/pthread_support.h [GC_WIN32_THREADS && GC_PTHREADS] (GC_lookup_by_pthread): Move declaration down. * include/private/pthread_support.h [GC_PTHREADS && !GC_WIN32_THREADS] (GC_lookup_by_pthread): Define as macro (to GC_lookup_thread). * pthread_stop_world.c [!NACL && GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread, GC_resume_thread, GC_is_thread_suspended): Use GC_lookup_by_pthread() instead of GC_lookup_thread(). * pthread_support.c [!GC_NO_PTHREAD_CANCEL && GC_PTHREADS && CANCEL_SAFE] (GC_pthread_cancel): Likewise. * pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2] (GC_pthread_join, GC_pthread_detach): Likewise. * pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 && GC_WIN32_THREADS] (GC_pthread_join, GC_pthread_detach): Wrap GC_lookup_by_pthread() call into LOCK/UNLOCK. * win32_threads.c [GC_PTHREADS] (GC_lookup_by_pthread): Refine comment; define id local variable; remove hv_guess local variable; replace break with return p; remove LOCK() and UNLOCK(); add assertion that the GC lock is held.
* Check out-of-memory and set in_thread_creation inside GC_new_threadIvan Maidanski2022-12-311-5/+0
| | | | | | | | | | | | | | | | | | | | | (refactoring) * pthread_support.c (GC_push_thread_structures): Add assertion that first_thread.tm.next and first_thread.status are null. * pthread_support.c (GC_new_thread): Rename id argument to self_id; add assertion that GC_in_thread_creation is off on entrance; set GC_in_thread_creation before GC_INTERNAL_MALLOC() first call and clear it after the second one; if crtn or result is null then ABORT instead of returning NULL. * pthread_support.c [!GC_DISABLE_INCREMENTAL] (GC_wait_for_gc_completion): Add assertion that GC_in_thread_creation is off before it is set. * pthread_support.c [!GC_WIN32_THREADS] (GC_register_my_thread_inner): Do not change GC_in_thread_creation value in this function directly; do not check the result of GC_new_thread(). * win32_threads.c (GC_register_my_thread_inner): Likewise. * win32_threads.c (GC_register_my_thread_inner): Remove assertion that the lock is held.
* Use GC_delete_thread instead of GC_delete_gc_thread_no_freeIvan Maidanski2022-12-311-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) This commit removes GC_delete_gc_thread_no_free, thus eliminating code duplication between GC_delete_thread and GC_delete_gc_thread_no_free. * include/private/pthread_support.h [GC_WIN32_THREADS && !GC_PTHREADS] (GC_delete_gc_thread_no_free): Rename to GC_delete_thread. * pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Add TODO item. * pthread_support.c (GC_delete_thread): Change argument from thread_id_t to GC_thread; update comment (copy it from GC_delete_gc_thread_no_free); change STATIC to GC_INNER_WIN32THREAD; define id as local variable; iterate over GC_threads[hv] chain until t is found. * pthread_support.c [GC_WIN32_THREADS && !MSWINCE] (GC_delete_thread): Move CloseHandle() call to the beginning of function. * pthread_support.c [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS] (GC_delete_thread): Do not call GC_win32_dll_lookup_thread; expand code of GC_delete_gc_thread_no_free. * pthread_support.c [!SN_TARGET_ORBIS && !SN_TARGET_PSP2] (GC_delete_gc_thread_no_free): Remove. * pthread_support.c [!THREAD_LOCAL_ALLOC] (GC_unregister_my_thread_inner): Do not cast me to void. * pthread_support.c (GC_unregister_my_thread_inner): Pass me (instead of thread_id_self()) to GC_delete_thread(). * pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2] (GC_pthread_join, GC_pthread_detach): Call GC_delete_thread() instead of GC_delete_gc_thread_no_free(), GC_INTERNAL_FREE(t->crtn) and GC_INTERNAL_FREE(t). * pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2] (GC_pthread_detach): Do not set DETACHED in t->flags if KNOWN_FINISHED(t). * win32_threads.c [!MSWINCE && !GC_PTHREADS] (GC_suspend): Remove assertion about GC_win32_dll_threads. * win32_threads.c [!MSWINCE && !GC_PTHREADS] (GC_suspend): Call GC_delete_thread() instead of GC_delete_gc_thread_no_free(). * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise. * win32_threads.c [MSWIN32 && !CONSOLE_LOG || MSWINCE] (GC_stop_world): Update comment.
* Disallow explicit unregister of non-main thread if registered by DllMainIvan Maidanski2022-12-191-11/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to match the behavior on non-Windows platforms (and to match the comment of GC_delete_thread). * include/private/pthread_support.h [GC_WIN32_THREADS && !GC_NO_THREADS_DISCOVERY && GC_ASSERTIONS] (GC_main_thread_id): Declare variable. * include/private/pthread_support.h [GC_WIN32_THREADS && !GC_NO_THREADS_DISCOVERY] (GC_delete_thread): Remove. * pthread_support.c (GC_delete_thread): Change GC_INNER_WIN32THREAD to STATIC. * pthread_support.c [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS] (GC_delete_thread): Call GC_win32_dll_lookup_thread instead of GC_lookup_thread and do not check its result. * pthread_support.c [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS] (GC_unregister_my_thread): Do not call GC_delete_thread (directly) if GC_win32_dll_threads; add assertion to check that the thread to b unregistered is main one if GC_win32_dll_threads; add comment. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (main_thread_id): Rename to GC_main_thread_id and change static to GC_INNER to STATIC. * win32_threads.c (GC_register_my_thread_inner): Update comment to mention GC_win32_dll_lookup_thread instead of GC_delete_thread. * win32_threads.c (GC_thr_init): Define self_id local variable and use it instead of main_thread_id; do not define main_thread_id as macro; do not undefine main_thread_id. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_DllMain): Call GC_win32_dll_lookup_thread() and GC_delete_gc_thread_no_free() instead of GC_delete_thread() (w/o a warning if the thread is not found).
* Fix double call of unregister_my_thread if thread registered by DllMainIvan Maidanski2022-12-191-2/+3
| | | | | | | | | | | | | | This, at least, avoids "Removing nonexistent thread" warning if GC_ExitThread or GC_endthreadex is called by client and DllMain-based thread registration is on. * win32_threads.c (GC_win32_start_inner): Add assertion that GC_win32_dll_threads is off. * win32_threads.c (GC_ExitThread): Do not call GC_unregister_my_thread if GC_win32_dll_threads (because the thread is to be unregistered by DllMain). * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_endthreadex): Likewise.
* Document that GC_unregister_my_thread result value is dummyIvan Maidanski2022-12-191-3/+3
| | | | | | | | | | * include/gc/gc.h [GC_THREADS] (GC_unregister_my_thread): Refine comment (mention that GC_SUCCESS is always returned). * tests/gctest.c [THREADS] (check_heap_stats): Cast call of GC_unregister_my_thread() to void. * win32_threads.c (GC_win32_start_inner, GC_ExitThread): Likewise. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_endthreadex): Likewise.
* Eliminate code defect of volatile read in assertion in Win32 GC_start_worldIvan Maidanski2022-12-121-2/+4
| | | | | | | | | (fix of commit 7eb49a4e6) Issue #362 (bdwgc). * win32_threads.c (GC_start_world): Cast away volatile for crtn->stack_end in the assertions.
* Move stack-related fields out of GC_thread to GC_stack_context_tIvan Maidanski2022-12-111-60/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) Issue #362 (bdwgc). * darwin_stop_world.c (GC_stack_range_for): Define and crtn local variable; use crtn instead of p to access stack_ptr, topOfStack, stack_end, altstack, altstack_size, normstack, normstack_size, backing_store_end, backing_store_ptr. * pthread_stop_world.c [!NACL] (GC_suspend_handler_inner, GC_push_all_stacks): Likewise. * pthread_support.c [!GC_NO_FINALIZATION] (GC_reset_finalizer_nested, GC_check_finalizer_nested): Likewise. * pthread_support.c [!GC_WIN32_THREADS] (GC_register_altstack): Likewise. * pthread_support.c (do_blocking_enter, do_blocking_leave, GC_set_stackbottom, GC_get_my_stackbottom, GC_call_with_gc_active): Likewise. * win32_threads.c (GC_push_stack_for, GC_get_next_stack): Likewise. * darwin_stop_world.c (GC_push_all_stacks): Use p->crtn instead of p to access traced_stack_sect. * win32_threads.c (GC_suspend, GC_stop_world, GC_start_world): Likewise. * include/private/pthread_support.h (GC_StackContext_Rep): New struct type (move dummy, stack_end, stack_ptr, last_stack_min, initial_stack_base, topOfStack, backing_store_end, backing_store_ptr, altstack, altstack_size, normstack, normstack_size, finalizer_nested, finalizer_skipped, traced_stack_sect from GC_Thread_Rep). * include/private/pthread_support.h [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS] (GC_StackContext_Rep.stack_end): Add volatile. * include/private/pthread_support.h [!GC_NO_FINALIZATION] (GC_StackContext_Rep.fnlz_pad): New field. * include/private/pthread_support.h (GC_stack_context_t): New type. * include/private/pthread_support.h (GC_Thread_Rep.crtn, GC_Thread_Rep.flags_pad): New field. * include/private/pthread_support.h [GC_NO_FINALIZATION] (GC_Thread_Rep.no_fnlz_pad): Remove field. * include/private/pthread_support.h (GC_threads): Move (and refine) comment from GC_Thread_Rep. * include/private/pthread_support.h [GC_WIN32_THREADS] (GC_record_stack_base): Change me argument to crtn. * pthread_stop_world.c [!NACL] (GC_store_stack_ptr): Likewise. * pthread_support.c (GC_record_stack_base): Likewise. * pthread_stop_world.c [NACL] (NACL_STORE_REGS, nacl_pre_syscall_hook, __nacl_suspend_thread_if_needed): Use p->crtn instead of p to access stack_ptr. * pthread_support.c (first_crtn): New static variable. * pthread_support.c (first_thread): Update comment. * pthread_support.c (first_thread_used): Remove variable. * pthread_support.c (GC_push_thread_structures): Push first_thread.crtn symbol * pthread_support.c (GC_push_thread_structures): Push first_crtn.backing_store_end instead of that in first_thread. * pthread_support.c [MPROTECT_VDB && GC_WIN32_THREADS] (GC_win32_unprotect_thread): Call GC_remove_protection() for t->crtn. * pthread_support.c (GC_new_thread): Use first_thread.crtn!=0 instead of first_thread_used; set first_thread.crtn to &first_crtn; allocate GC_StackContext_Rep object using GC_INTERNAL_MALLOC() and store the pointer to result->crtn. * pthread_support.c [CPPCHECK] (GC_new_thread): Call GC_noop1() for first_thread.flags_pad, for first_crtn.dummy instead of result->dummy, and for first_crtn.fnlz_pad instead of result->no_fnlz_pad. * pthread_support.c (GC_delete_thread): Call GC_INTERNAL_FREE(p->crtn) along with that for p. * pthread_support.c [CAN_HANDLE_FORK && (!THREAD_SANITIZER || !CAN_CALL_ATFORK)] (GC_remove_all_threads_but_me): Likewise. * pthread_support.c [GC_PTHREADS] (GC_pthread_join, GC_pthread_detach): Likewise. * pthread_support.c (GC_segment_is_thread_stack, GC_greatest_stack_base_below): Use p->crtn instead of p to access stack_end. * pthread_support.c (GC_call_with_gc_active): Move assertions about me fields to be after LOCK; add assertion that me->crtn==crtn. * win32_threads.c (dll_thread_table): Make it static. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (dll_crtn_table): New static variable. * win32_threads.c (GC_register_my_thread_inner): Reformat comment; set me->crtn. * win32_threads.c (GC_push_stack_for): Define stack_end local variable; immediately return (zero) if stack_end is NULL. * win32_threads.c (GC_push_all_stacks): Call GC_push_stack_for() (and increment nthreads) even if stack_end is NULL. * win32_threads.c (GC_get_next_stack): Rename s local variable to stack_end.
* Fix 'GC_write called with write_disabled' assertion in GC_suspendIvan Maidanski2022-12-091-1/+2
| | | | | | | | | | | | | | (fix of commit bc1866b14) Reproduced only if DEBUG_THREADS is defined. Do not call GC_log_printf(), even indirectly from GC_stop_world() with GC_write_cs acquired. * pthread_support.c [DEBUG_THREADS] (GC_delete_thread, GC_delete_gc_thread_no_free): Do not call GC_log_printf() if MSWINCE or MSWIN32 and not CONSOLE_LOG. * win32_threads.c [DEBUG_THREADS] (GC_suspend): Likewise.
* Avoid code duplication between pthread_support.c and win32_threads.cIvan Maidanski2022-12-061-1462/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * CMakeLists.txt [CMAKE_USE_PTHREADS_INIT || CMAKE_USE_WIN32_THREADS_INIT] (SRC): Include pthread_start.c and pthread_support.c for Win32 platform. * Makefile.am [THREADS] (libgc_la_SOURCES): Likewise. * NT_MAKEFILE [ENABLE_STATIC] (OBJS): Add pthread_start.obj, pthread_support.obj. * include/private/gc_locks.h [LINT2 || GC_WIN32_THREADS] (NO_PTHREAD_TRYLOCK): Do not define if already defined; add comment. * include/private/gcconfig.h [GC_PTHREADS && !GC_PTHREADS_PARAMARK && !__MINGW32__] (GC_PTHREADS_PARAMARK): Do not define unless PARALLEL_MARK. * include/private/pthread_support.h (thread_id_self, THREAD_ID_EQUAL, ADDR_LIMIT, MAX_MARKERS, GC_PTHREAD_PTRVAL): Define macro. * include/private/pthread_support.h (GC_win32_dll_threads, GC_available_markers_m1, GC_required_markers_cnt, GC_marker_sp, GC_marker_last_stack_min, GC_marker_Id): Declare global variable. * include/private/pthread_support.h (GC_init_win32_thread_naming, GC_mark_thread, GC_new_thread, GC_record_stack_base, GC_register_my_thread_inner, GC_lookup_by_pthread, GC_setup_atfork, GC_win32_cache_self_pthread, GC_delete_gc_thread_no_free, GC_win32_dll_lookup_thread, GC_delete_thread, GC_win32_unprotect_thread, GC_wait_for_gc_completion): Declare. * include/private/pthread_support.h [GC_PTHREADS] (GC_pthread_start_inner, GC_start_rtn_prepare_thread): Declare even for GC_WIN32_THREADS. * misc.c [!THREADS] (GC_call_with_gc_active, GC_do_blocking_inner): Update comment to refer to pthread_support.c. * pthread_start.c [GC_PTHREADS] (GC_pthread_start_inner): Define even for GC_WIN32_THREADS. * pthread_support.c: Do not skip this file for GC_WIN32_THREADS; adjust includes for Win32. * pthread_support.c (GC_INNER_WIN32THREAD): New macro. * pthread_support.c (GC_init_win32_thread_naming, GC_win32_unprotect_thread): New function. * pthread_support.c (setThreadDescription_fn, set_marker_thread_name): Move from win32_threads.c. * pthread_support.c (available_markers_m1): Rename to GC_available_markers_m1. * win32_threads.c (available_markers_m1): Likewise. * pthread_support.c (required_markers_cnt): Rename to GC_required_markers_cnt. * win32_threads.c (required_markers_cnt): Likewise. * pthread_support.c (GC_mark_thread, GC_start_mark_threads_inner, GC_push_thread_structures, GC_count_threads, GC_new_thread, GC_delete_thread, GC_delete_gc_thread_no_free, GC_lookup_thread, GC_reset_finalizer_nested, GC_check_finalizer_nested, GC_is_thread_tsd_valid, GC_thread_is_registered, GC_register_altstack, GC_segment_is_thread_stack, GC_wait_for_gc_completion, GC_remove_all_threads_but_me, fork_child_proc, GC_record_stack_base, GC_init_parallel, GC_pthread_sigmask, GC_set_stackbottom, GC_get_my_stackbottom, GC_call_with_gc_active, GC_unregister_my_thread, GC_unregister_my_thread_inner, GC_thread_exit_proc, GC_pthread_join, GC_pthread_detach, GC_pthread_sigmask, GC_pthread_create): Adjust function for Win32. * win32_threads.c (GC_lock_holder, GC_win32_dll_threads, IE_t, GC_thr_initialized, GC_need_to_lock, ADDR_LIMIT, GC_thread, GC_vthread, GC_threads, first_thread, GC_new_thread, GC_in_thread_creation, GC_record_stack_base, GC_lookup_thread, CHECK_LOOKUP_MY_THREAD, GC_reset_finalizer_nested, GC_check_finalizer_nested, GC_is_thread_tsd_valid, GC_thread_is_registered, GC_register_altstack, UNPROTECT_THREAD, GC_PTHREAD_PTRVAL, GC_delete_gc_thread_no_free, GC_delete_thread, GC_allow_register_threads, GC_register_my_thread, GC_set_stackbottom, GC_wait_for_gc_completion, GC_unregister_my_thread, GC_do_blocking_inner, GC_call_with_gc_active, GC_get_my_stackbottom, GC_remove_all_threads_but_me, fork_prepare_proc, fork_parent_proc, fork_child_proc, GC_atfork_prepare, GC_atfork_parent, GC_atfork_child, GC_setup_atfork, GC_push_thread_structures, marker_sp, set_marker_thread_name, setThreadDescription_fn, GC_mark_thread, required_markers_cnt, GC_set_markers_count, START_MARK_THREADS, start_info, GC_pthread_join, GC_pthread_create, GC_pthread_start_inner, GC_pthread_start, GC_thread_exit_proc, GC_pthread_detach, GC_check_tls, GC_init_parallel, GC_lock, GC_mark_thread_local_free_lists): Remove. * win32_threads.c [GC_PTHREADS_PARAMARK] (mark_cv, GC_start_mark_threads_inner, GC_mark_lock_holder, SET_MARK_LOCK_HOLDER, UNSET_MARK_LOCK_HOLDER, mark_mutex, builder_cv, GC_acquire_mark_lock, GC_release_mark_lock, GC_wait_builder, GC_wait_for_reclaim, GC_notify_all_builder, GC_wait_marker, GC_notify_all_marker, * win32_threads.c [GC_PTHREADS] (pthread_create, pthread_join, pthread_detach, pthread_sigmask): Do not undefine. * win32_threads.c [CAN_CALL_ATFORK]: Do not include unistd.h. * win32_threads.c (GC_register_my_thread_inner): Change type of me local variable from GC_vthread to GC_thread. * win32_threads.c (GC_win32_dll_lookup_thread, GC_win32_cache_self_pthread): New GC_INNER function. * win32_threads.c (GC_suspend, GC_start_world, GC_push_stack_for): Use GC_win32_unprotect_thread() instead of UNPROTECT_THREAD(). * win32_threads.c (marker_last_stack_min): Rename to GC_marker_last_stack_min. * win32_threads.c (GC_thr_init): Call GC_init_win32_thread_naming().
* Fix use of unset errno after pthread_sigmask callsIvan Maidanski2022-11-131-4/+2
| | | | | | | | | | (fix of commit 95947bdc5) * pthread_support.c [PARALLEL_MARK && !NO_MARKER_SPECIAL_SIGMASK] (GC_start_mark_threads_inner): Do not pass errno value to WARN() calls (because pthread_sigmask does not set errno). * win32_threads.c [PARALLEL_MARK && GC_PTHREADS_PARAMARK && !NO_MARKER_SPECIAL_SIGMASK] (GC_start_mark_threads_inner): Likewise.
* Eliminate 'cast signed to bigger unsigned' CSA warning in WARN callsIvan Maidanski2022-11-011-5/+8
| | | | | | | | | | | | * pthread_support.c [HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG] (set_marker_thread_name): Cast WARN argument to signed_word. * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise. * pthread_support.c [GC_LINUX_THREADS && !HOST_ANDROID && !NACL] (GC_get_nprocs): Likewise. * pthread_support.c (GC_thr_init): Likewise. * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Likewise.
* Fix negative heap size values reported in WARNIvan Maidanski2022-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #496 (bdwgc). WARN_PRIuPTR is now used to print unsigned values in WARN() calls. Also, byte values are replaced with KiB ones in some WARN() calls. * allchblk.c (GC_allochblk_nth): Use WARN_PRIuPTR specifier instead of WARN_PRIdPTR. * alloc.c (GC_expand_hp_inner, GC_collect_or_expand): Likewise. * headers.c (GC_scratch_alloc): Likewise. * mark.c (alloc_mark_stack): Likewise. * misc.c (GC_enable): Likewise. * os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Likewise. * os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise. * win32_threads.c (GC_delete_thread): Likewise. * allchblk.c (GC_allochblk_nth): Print KiB value instead of in bytes in WARN message. * alloc.c (GC_expand_hp_inner): Likewise. * misc.c (GC_enable): Likewise. * alloc.c (GC_expand_hp_inner): Remove unneeded cast of bytes to word. * headers.c (GC_scratch_alloc): Likewise. * alloc.c [(!AMIGA || !GC_AMIGA_FASTALLOC) && USE_MUNMAP] (GC_collect_or_expand): Add assertion to indicate that there is no underflow in GC_heapsize-GC_unmapped_bytes. * include/private/gc_priv.h (WARN): Update comment. * include/private/gc_priv.h [!WARN_PRIdPTR] (WARN_PRIuPTR): Define.
* Eliminate 'NUMERIC_THREAD_ID is unknown' cppcheck warningIvan Maidanski2022-10-191-1/+1
| | | | | | | | (fix of commit 6b2980ab6) * win32_threads.c [PARALLEL_MARK && GC_PTHREADS_PARAMARK && GC_ASSERTIONS] (NUMERIC_THREAD_ID): Define only if USE_PTHREAD_LOCKS is not defined (instead of checking NUMERIC_THREAD_ID).
* Eliminate 'boolean result used in bitwise op' cppcheck FP in GC_thr_initIvan Maidanski2022-10-191-1/+1
| | | | | | | | | | (fix of commit d692eb432) * pthread_support.c (GC_thr_init): Put &GC_threads into parentheses in assertion. * win32_threads.c (GC_thr_init): Likewise. * thread_local_alloc.c [USE_CUSTOM_SPECIFIC] (GC_init_thread_local): Put &GC_thread_key into parentheses in assertion.
* Move pthread_atfork() call to a separate functionIvan Maidanski2022-10-191-13/+17
| | | | | | | | | | | | | | | | (refactoring) * pthread_support.c [CAN_HANDLE_FORK] (store_to_threads_table, GC_remove_all_threads_but_me): Move definition down (to be close to fork_prepare_proc). * pthread_support.c [CAN_HANDLE_FORK]: Reformat comment; adjust code indentation. * pthread_support.c [CAN_HANDLE_FORK] (GC_setup_atfork): New STATIC function (move code from GC_thr_init). * win32_threads.c [CAN_HANDLE_FORK] (GC_setup_atfork): Likewise. * pthread_support.c [CAN_HANDLE_FORK] (GC_thr_init): Call GC_setup_atfork(). * win32_threads.c [CAN_HANDLE_FORK] (GC_thr_init): Likewise.
* Rename thread_args and GC_main_thread in win32_threads.cIvan Maidanski2022-10-191-36/+38
| | | | | | | | | | | | | | | | | | | | | | (refactoring) This is to match the code (naming style) of pthread_support.c file. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_main_thread): Rename to main_thread_id; change STATIC to static. * win32_threads.c (thread_args): Rename win32_start_info; rename start field to start_routine; rename param field to arg. * win32_threads.c (GC_win32_start_inner): Rename start local variable to start_routine; rename param local variable to start_arg; rename args local variable to psi. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_WINMAIN_REDIRECT] (main_thread_start): Rename args local variable to main_args. * win32_threads.c (GC_thr_init): Use main_thread_id variable instead of GC_main_thread. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise.
* Unify GC_[mark_]lock_holder variable definitionIvan Maidanski2022-10-171-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS] (NO_THREAD): Define in a single place. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (UNSET_LOCK_HOLDER): Likewise. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (GC_lock_holder): Declare in a single place. * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS] (NO_THREAD): Change DWORD to unsigned long. * include/private/gc_locks.h [GC_WIN32_THREADS && !USE_PTHREAD_LOCKS && GC_ASSERTIONS] (GC_lock_holder): Likewise. * win32_threads.c [!USE_PTHREAD_LOCKS && GC_ASSERTIONS] (GC_lock_holder): Likewise. * win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK && GC_ASSERTIONS] (GC_mark_lock_holder): Likewise. * include/private/gc_locks.h [(GC_WIN32_THREADS && !USE_PTHREAD_LOCKS || GC_PTHREADS) && GC_ASSERTIONS] (SET_LOCK_HOLDER, UNSET_LOCK_HOLDER): Cast to void. * win32_threads.c [GC_ASSERTIONS] (GC_lock_holder): Define in a single place (in the file).
* Fix double initialization of main thread local free lists on Win32Ivan Maidanski2022-10-141-8/+10
| | | | | | | | | | * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread_inner): Update comment; do not call GC_init_thread_local(). * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread): Call GC_init_thread_local() both after GC_register_my_thread_inner() and GC_record_stack_base() calls (in case of return GC_SUCCESS). * win32_threads.c [GC_PTHREADS && THREAD_LOCAL_ALLOC] (GC_pthread_start_inner): Call GC_init_thread_local().
* Fix missing result check of pthread_attr_getdetachstate in pthread_createIvan Maidanski2022-10-111-7/+4
| | | | | | | | | * pthread_support.c (pthread_create): Call ABORT() if pthread_attr_getdetachstate() has failed. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise. * win32_threads.c [GC_PTHREADS] (start_info.detached): Change type from GC_bool to int (to match the type of the 2nd argument of pthread_attr_getdetachstate).
* Remove GC_mark_threads variableIvan Maidanski2022-10-061-2/+0
| | | | | | | | | | | | (refactoring) * pthread_support.c [PARALLEL_MARK] (GC_mark_threads): Remove static variable. * pthread_support.c [PARALLEL_MARK] (GC_start_mark_threads_inner): Define new_thread local variable and use it in pthread_create() call instead of GC_mark_threads. * win32_threads.c [PARALLEL_MARK]: Remove comment about GC_mark_threads.
* Define GC_thread type in a single place both for pthreads and Win32Ivan Maidanski2022-10-061-175/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * include/private/pthread_support.h: Add title comment. * include/private/pthread_support.h: Replace GC_PTHREADS&&!GC_WIN32_THREADS condition to THREADS. * include/private/pthread_support.h [GC_PTHREADS || GC_PTHREADS_PARAMARK]: Include pthread.h. * include/private/pthread_support.h [GC_WIN32_THREADS] (thread_id_t): Define as DWORD. * include/private/pthread_support.h [!GC_NO_THREADS_DISCOVERY && GC_WIN32_THREADS] (GC_Thread_Rep.tm): Add in_use and long_in_use union fields (moved from win32_threads.c). * include/private/pthread_support.h (GC_Thread_Rep.tm.next, GC_Thread_Rep.stack_end): Update comment. * include/private/pthread_support.h (GC_Thread_Rep.id): Add comment. * include/private/pthread_support.h [USE_TKILL_ON_ANDROID] (GC_Thread_Rep.kernel_id): Move field down (to be after stack_ptr). * include/private/pthread_support.h [GC_WIN32_THREADS && GC_PTHREADS] (GC_Thread_Rep.pthread_id): New field (moved from win32_threads.c). * include/private/pthread_support.h [GC_NO_FINALIZATION] (GC_Thread_Rep.no_fnlz_pad): Likewise. * include/private/pthread_support.h [GC_WIN32_THREADS] (GC_Thread_Rep.last_stack_min): Likewise. * include/private/pthread_support.h [GC_WIN32_THREADS && I386] (GC_Thread_Rep.initial_stack_base): Likewise. * include/private/pthread_support.h [GC_WIN32_THREADS && !MSWINCE] (GC_Thread_Rep.handle): Likewise. * include/private/pthread_support.h [RETRY_GET_THREAD_CONTEXT] (GC_Thread_Rep.context_sp, GC_Thread_Rep.context_regs): Likewise. * include/private/pthread_support.h (GC_Thread_Rep.flags): Move field up (to be right after pthread_id one). * include/private/pthread_support.h (FINISHED, DETACHED, MAIN_THREAD, DISABLED_GC, DO_BLOCKING, KNOWN_FINISHED): Move macro definition up to stay close to flags field. * include/private/pthread_support.h [!GC_PTHREADS] (KNOWN_FINISHED): Define to FALSE. * include/private/pthread_support.h (DETACHED): Define only if GC_PTHREADS. * include/private/pthread_support.h (GC_Thread_Rep.status): Likewise. * include/private/pthread_support.h (MAIN_THREAD, DISABLED_GC): Do not define if GC_WIN32_THREADS. * include/private/pthread_support.h (GC_Thread_Rep.altstack, GC_Thread_Rep.altstack_size, GC_Thread_Rep.normstack, GC_Thread_Rep.normstack_size): Likewise. * include/private/pthread_support.h [GC_WIN32_THREADS] (IS_SUSPENDED): Define macro (moved from win32_threads.c). * include/private/pthread_support.h [MSWINCE || GC_WIN32_THREADS] (THREAD_HANDLE): Likewise. * include/private/pthread_support.h [GC_WIN32_THREADS] (THREAD_TABLE_INDEX): Likewise. * include/private/gcconfig.h [GC_WIN32_THREADS] (PUSHED_REGS_COUNT): Likewise. * include/private/gcconfig.h [GC_PTHREADS && !GC_PTHREADS_PARAMARK && !__MINGW32__] (GC_PTHREADS_PARAMARK): Likewise. * include/private/pthread_support.h [!GC_NO_FINALIZATION] (GC_Thread_Rep.finalizer_nested, GC_Thread_Rep.finalizer_skipped): Move field up to be right after flags one. * include/private/pthread_support.h [SIGNAL_BASED_STOP_WORLD] (GC_Thread_Rep.last_stop_count, GC_Thread_Rep.ext_suspend_cnt): Reformat comment. * include/private/pthread_support.h (GC_Thread_Rep.traced_stack_sect): Likewise. * include/private/pthread_support.h (GC_inner_start_routine, GC_start_rtn_prepare_thread): Do not declare if GC_WIN32_THREADS. * include/private/pthread_support.h (GC_thread_exit_proc): Declare only if GC_PTHREADS. * pthread_start.c: Do not include pthread.h. * pthread_support.c: Likewise. * win32_threads.c [GC_PTHREADS || GC_WIN32_PTHREADS || GC_PTHREADS_PARAMARK]: Likewise. * win32_threads.c: Include pthread_support.h instead of gc_priv.h. * win32_threads.c [THREAD_LOCAL_ALLOC]: Do not include thread_local_alloc.h directly. * win32_threads.c [GC_PTHREADS] (GC_thread_exit_proc): Remove static function declaration. * win32_threads.c [GC_ASSERTIONS] (GC_thr_initialized, GC_threads, GC_lookup_thread_inner): Change STATIC to GC_INNER. * win32_threads.c (thread_id_t, GC_Thread_Rep, THREAD_TABLE_SZ, THREAD_TABLE_INDEX, PUSHED_REGS_COUNT, GC_PTHREADS_PARAMARK): Do not define. * win32_threads.c (GC_lookup_thread_inner): Rename to GC_lookup_thread. * win32_threads.c [GC_PTHREADS] (GC_lookup_pthread): Rename to GC_lookup_by_pthread. * win32_threads.c [GC_PTHREADS] (GC_thread_exit_proc): Change STATIC to GC_INNER_PTHRSTART.
* Move GC_NO_THREADS_DISCOVERY definition to gcconfig.hIvan Maidanski2022-10-061-9/+1
| | | | | | | | | | | | | | | (refactoring) * darwin_stop_world.c (GC_use_threads_discovery): Do not check DARWIN_DONT_PARSE_STACK. * include/private/gcconfig.h [!GC_NO_THREADS_DISCOVERY] (GC_NO_THREADS_DISCOVERY): Define macro (where the mode is unsupported); move comment from win32_threads.c. * include/private/gcconfig.h [GC_DISCOVER_TASK_THREADS && GC_NO_THREADS_DISCOVERY && !CPPCHECK]: Issue error. * win32_threads.c: Replace ((GC_DLL||GC_INSIDE_DLL) && !NO_CRT && !GC_NO_THREADS_DISCOVERY && !MSWINCE && !THREAD_LOCAL_ALLOC && !GC_PTHREADS) with !GC_NO_THREADS_DISCOVERY.
* Unify GC_Thread_Rep and thread id type in win32_threads.cIvan Maidanski2022-10-061-171/+180
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * win32_threads.c (thread_id_t): Define type. * win32_threads.c (GC_Thread_Rep.id, GC_main_thread, GC_pthread_map_cache): Change type from DWORD to thread_id_t. * win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK] (GC_marker_Id): Likewise. * win32_threads.c (GC_Thread_Rep.stack_base): Rename to stack_end; update comment. * win32_threads.c (GC_Thread_Rep.thread_blocked_sp): Rename to stack_ptr; update comment. * win32_threads.c [GC_NO_FINALIZATION] (GC_Thread_Rep.no_fnlz_pad): New field (to force word-aligned next fields). * win32_threads.c (GC_Thread_Rep.suspended): Remove (use flags and IS_SUSPENDED instead). * win32_threads.c (GC_Thread_Rep.flags, FINISHED): Define even if not GC_PTHREADS. * win32_threads.c (GC_new_thread, GC_register_my_thread_inner, GC_register_my_thread_inner, GC_delete_thread): Rename thread_id to id and change its type from DWORD to thread_id_t. * win32_threads.c (GC_thread_is_registered, GC_register_my_thread, GC_unregister_my_thread, GC_do_blocking_inner, GC_call_with_gc_active, GC_get_my_stackbottom, GC_remove_all_threads_but_me, GC_stop_world, GC_start_world, GC_push_all_stacks, GC_pthread_start_inner, GC_DllMain): Rename thread_id local variable to self_id and change its type from DWORD to thread_id_t. * win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK] (GC_wait_marker, GC_notify_all_marker): Likewise. * win32_threads.c (GC_new_thread): Remove comment about the pthreads version; assert result->flags is zero even if not GC_PTHREADS; do not use thread_blocked_sp. * win32_threads.c [GC_NO_FINALIZATION && CPPCHECK] (GC_new_thread): Call GC_noop1(result->no_fnlz_pad[0]). * win32_threads.c (GC_record_stack_base): Change me argument type from GC_vthread to GC_thread. * win32_threads.c (GC_delete_gc_thread_no_free): Remove id local variable. * win32_threads.c [GC_PTHREADS] (GC_register_my_thread, GC_remove_all_threads_but_me, GC_pthread_join, GC_pthread_detach): Replace p->flags&FINISHED to KNOWN_FINISHED(p). * win32_threads.c [IA64] (GC_do_blocking_inner): Rename stack_ptr local variable to bs_hi. * win32_threads.c (GC_do_blocking_inner, GC_call_with_gc_active, GC_set_stackbottom, GC_stop_world, GC_push_stack_for): Replace p->thread_blocked_sp to p->flags&DO_BLOCKING. * win32_threads.c (GC_do_blocking_inner, GC_call_with_gc_active): Do not set p->stack_ptr to NULL. * win32_threads.c [GC_PTHREADS] (GC_lookup_pthread): Rename id argument to thread. * win32_threads.c [GC_PTHREADS && CAN_HANDLE_FORK] (GC_remove_all_threads_but_me, GC_pthread_start_inner): Rename pthread_id local variable to self. * win32_threads.c (GC_push_stack_for): Rename me argument to self_id and change its type from DWORD to thread_id_t. * win32_threads.c (GC_stop_world, GC_start_world, GC_push_stack_for): Replace p->suspended with p->flags&IS_SUSPENDED. * win32_threads.c [GC_PTHREADS] (GC_pthread_join, GC_pthread_detach): Rename pthread_id argument to thread.
* Fix 'scope of hv can be reduced' cppcheck warning in GC_lookup_pthreadIvan Maidanski2022-10-011-1/+2
| | | | | | | (fix of commit 48a01ee1c) * win32_threads.c [GC_PTHREADS] (GC_lookup_pthread): Move hv local variable definition to the inner block where it is used.
* Rename stack[_size] in GC_Thread_Rep and GC_register_altstackIvan Maidanski2022-10-011-4/+4
| | | | | | | | | | | | | | | | | | | | | | (refactoring) * darwin_stop_world.c [DARWIN_DONT_PARSE_STACK] (GC_stack_range_for): Rename p->stack[_size] to p->normstack[_size]. * pthread_support.c (GC_thr_init): Likewise. * include/gc/gc.h (GC_register_altstack): Rename stack_start to normstack and stack_size to normstack_size in comment, respectively. * include/private/pthread_support.h (GC_Thread_Rep.stack): Rename to normstack. * include/private/pthread_support.h (GC_Thread_Rep.stack_size): Rename to normstack_size. * pthread_support.c (main_stack): Rename to main_normstack. * pthread_support.c (main_stack_size): Rename to main_normstack_size. * pthread_support.c (GC_register_altstack): Rename stack to normstack and stack_size to normstack_size arguments, respectively. * win32_threads.c (GC_register_altstack): Likewise. * pthread_support.c [(HAVE_PTHREAD_ATTR_GET_NP || HAVE_PTHREAD_GETATTR_NP) && IA64]: Change stack_base to "stack base" in comment.
* Fix typo in comment belonging to dll_thread_tableIvan Maidanski2022-09-301-1/+1
| | | | * win32_threads.c (dll_thread_table): Fix a typo ("use") in comment.
* Consistent naming of GC_thread local variablesIvan Maidanski2022-09-301-99/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) Also, change "while" to "for" statement to iterate over GC_threads. * darwin_stop_world.c (GC_stack_range_for): Add pfound_me argument; update comment; set *pfound_me to TRUE if thread is my_thread. * win32_threads.c (GC_push_stack_for): Likewise. * darwin_stop_world.c (GC_push_all_stacks): Do not define listcount local variable if DARWIN_DONT_PARSE_STACK. * darwin_stop_world.c (GC_push_all_stacks): Pass &found_me to GC_stack_range_for (instead of setting it to TRUE directly). * win32_threads.c (GC_push_all_stacks): Likewise. * darwin_stop_world.c [DARWIN_DONT_PARSE_STACK] (GC_push_all_stacks): Do not initialize act_list and listcount local variables. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS && THREAD_SANITIZER] (GC_lookup_thread_async): Change while statement to for one. * pthread_support.c [DEBUG_THREADS] (GC_count_threads): Likewise. * pthread_support.c (GC_lookup_thread): Likewise. * win32_threads.c (GC_lookup_thread_inner, GC_delete_thread): Likewise. * pthread_stop_world.c (GC_push_all_stacks): Define and use is_self local variable. * win32_threads.c (GC_push_stack_for): Likewise. * pthread_support.c [DEBUG_THREADS] (GC_count_threads): Rename th local variable to p. * win32_threads.c (GC_Thread_Rep.thread_blocked_sp, GC_lookup_pthread): Refine comment. * win32_threads.c (GC_new_thread, GC_delete_thread): Rename id argument to thread_id. * win32_threads.c (GC_lookup_pthread): Remove GC_lookup_pthread label. * win32_threads.c (GC_lookup_thread_inner): Reformat comment. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_lookup_thread_inner): Define and use t local variable. * win32_threads.c (GC_stop_world, GC_start_world, GC_push_all_stacks, GC_get_next_stack): Rename t to p local variable. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_stop_world): Change type of t local from GC_vthread to GC_thread.
* Fix missing GC_CALLBACK for GC_waitForSingleObjectInfiniteIvan Maidanski2022-09-281-1/+1
| | | | | | | (fix of commit 6713d8473) * win32_threads.c [GC_WINMAIN_REDIRECT] (GC_waitForSingleObjectInfinite): Add GC_CALLBACK.
* Define internal macro NO_SEH_AVAILABLE where SEH is absentIvan Maidanski2022-09-271-2/+2
| | | | | | | | | | | | | | | (refactoring) * include/private/gc_priv.h [WRAP_MARK_SOME]: Replace !MSWIN32&&!MSWINCE||__GNUC__ to NO_SEH_AVAILABLE in ifdef. * mark.c [WRAP_MARK_SOME] (GC_mark_some): Likewise. * os_dep.c [WRAP_MARK_SOME] (GC_fault_handler_t, GC_jmp_buf): Likewise. * include/private/gcconfig.h [!MSWIN32 && !MSWINCE || __GNUC__ || NO_CRT] (NO_SEH_AVAILABLE): Define. * mark.c [WRAP_MARK_SOME] (GC_mark_some): Refine comments. * os_dep.c (MIN_PAGE_SIZE): Define regardless of WRAP_MARK_SOME. * win32_threads.c (GC_win32_start_inner): Replace !__GNUC__&&!NO_CRT to !NO_SEH_AVAILABLE in ifdef.
* Adjust naming of Win32/64 and x86/64 words in comments and documentationIvan Maidanski2022-09-261-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ChangeLog: Replace i386 and X86 to x86; replace x86_64 and amd64 to x64; replace "Win32 pthreads" to pthreads-win32; lower case win32s, x86, x64; replace win32 to Win32; replace "MS Windows" to Windows (in documentation and comments). * NT_MAKEFILE: Likewise. * README.md: Likewise. * configure.ac: Likewise. * cord/tests/de_win.c: Likewise. * doc/README.macros: Likewise. * doc/README.solaris2: Likewise. * doc/README.win32: Likewise. * doc/README.win64: Likewise. * doc/debugging.md: Likewise. * doc/leak.md: Likewise. * doc/overview.md: Likewise. * doc/porting.md: Likewise. * extra/msvc_dbg.c: Likewise. * finalize.c: Likewise. * include/gc/cord.h: Likewise. * include/gc/gc.h: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * include/private/pthread_stop_world.h: Likewise. * mach_dep.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * os_dep.c: Likewise. * tools/threadlibs.c: Likewise. * win32_threads.c: Likewise. * cord/tests/de.c (WIN32): Remove misleading comment. * misc.c (GC_enable_incremental): Change comment about win32s to TODO item.
* Remove unreachable code in GC_lookup_pthreadIvan Maidanski2022-09-221-19/+4
| | | | | | | | | (refactoring) * win32_threads.c [GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_lookup_pthread): Remove unreachable code (because GC_PTHREADS implies GC_NO_THREADS_DISCOVERY, as of now); add TODO to re-add the code when threads discovery will be supported with pthreads.
* Fix loop condition over dll_thread_table in GC_lookup_pthread (Win32)Ivan Maidanski2022-09-221-1/+1
| | | | | | | | | | (fix of commit 2fe9e9d55) Break the loop (over dll_thread_table elements) in GC_lookup_pthread when pthread_id matches id (provided the element is in use). * win32_threads.c [GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_lookup_pthread): Inverse THREAD_EQUAL() condition in for statement.
* Use cast to void instead of the attribute to indicate unused argumentsIvan Maidanski2022-09-151-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * CMakeLists.txt [BORLAND] (add_compile_options): Remove "/w-par"; reorder options. * CMakeLists.txt [!BORLAND && MSVC] (add_compile_options): Remove "/wd4100"; update comment. * NT_MAKEFILE (.c.obj): Likewise. * allchblk.c [!NO_DEBUGGING || GC_ASSERTIONS] (add_hb_sz): Use UNUSED_ARG() instead of GC_ATTR_UNUSED. * allchblk.c [USE_MUNMAP] (GC_adjust_num_unmapped): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (pop_in_progress, reset_back_edge, update_max_height): Likewise. * checksums.c [CHECKSUMS] (GC_add_block): Likewise. * darwin_stop_world.c (GC_stack_range_for): Likewise. * dbg_mlc.c (GC_store_debug_info_inner, GC_debug_change_stubborn, GC_check_heap_block): Likewise. * finalize.c [!GC_NO_FINALIZATION] (GC_null_finalize_mark_proc): Likewise. * gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_fake_mark_proc): Likewise. * mallocx.c [!CPPCHECK] (GC_change_stubborn): Likewise. * mark.c (GC_noop6, clear_marks_for_block): Likewise. * mark.c [WRAP_MARK_SOME && (MSWIN32 || MSWINCE) && __GNUC__] (mark_ex_handler): Likewise. * mark.c [GC_DISABLE_INCREMENTAL] (GC_push_conditional): Likewise. * mark_rts.c (GC_push_current_stack, GC_push_roots): Likewise. * misc.c (GC_default_oom_fn, GC_set_handle_fork): Likewise. * misc.c [THREADS && !SIGNAL_BASED_STOP_WORLD] (GC_set_suspend_signal, GC_set_thr_restart_signal): Likewise. * misc.c [THREADS && UNIX_LIKE && !NO_GETCONTEXT] (callee_saves_pushed_dummy_fn): Likewise. * misc.c [!THREADS] (GC_do_blocking_inner): Likewise. * misc.c [!PARALLEL_MARK] (GC_set_markers_count): Likewise. * os_dep.c [OPENBSD] (GC_fault_handler_openbsd): Likewise. * os_dep.c [NEED_FIND_LIMIT || WRAP_MARK_SOME && !MSWIN32 && !MSWINCE || USE_PROC_FOR_LIBRARIES && THREADS] (GC_fault_handler): Likewise. * os_dep.c [!HAVE_GET_STACK_BASE && !NEED_FIND_LIMIT] (GC_get_stack_base): Likewise. * os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise_state, catch_exception_raise_state_identity, catch_exception_raise): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS && !SUSPEND_HANDLER_NO_CONTEXT] (GC_suspend_sigaction): Likewise. * pthread_stop_world.c [!NACL && !GC_OPENBSD_UTHREADS] (GC_suspend_handler_inner): Likewise. * pthread_support.c (GC_do_blocking_inner): Likewise. * pthread_support.c [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_blocked): Likewise. * tests/gctest.c [!DBG_HDRS_ALL] (fail_proc1): Likewise. * tests/gctest.c [(MSWIN32 && !__MINGW32__ || MSWINCE) && !NO_WINMAIN_ENTRY] (WinMain): Likewise. * tests/gctest.c [!PCR && !GC_WIN32_THREADS && !GC_PTHREADS && CPPCHECK && RTEMS] (Init): Likewise. * tests/gctest.c [GC_WIN32_THREADS && !GC_PTHREADS] (thr_run_one_test): Likewise. * tests/gctest.c [MSWINCE] (thr_window): Likewise. * tests/gctest.c [GC_PTHREADS] (thr_run_one_test): Likewise. * typd_mlc.c (GC_array_mark_proc): Likewise. * win32_threads.c (GC_register_altstack, GC_do_blocking_inner): Likewise. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise. * cord/cordxtra.c (CORD_ATTR_UNUSED): Remove. * include/private/gc_priv.h [!GC_ATTR_UNUSED] (GC_ATTR_UNUSED): Likewise. * cord/cordxtra.c (CORD_nul_func): Cast unused argument to void instead of using CORD_ATTR_UNUSED. * cord/cordxtra.c [!GC_NO_FINALIZATION] (CORD_lf_close_proc): Likewise. * include/private/gc_priv.h [!UNUSED_ARG] (UNUSED_ARG): Define macro.
* Prevent (fix) parallel custom mark procs run in single-threaded clientsIvan Maidanski2022-06-011-15/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the collector is built with parallel marker support then marking is performed in parallel on multi-core targets. Thus, if the client provides custom mark procedures, then they could be executed in parallel. In case of a single-threaded client (developed for the older libgc version with the parallel mark support off), its custom mark procedures might not be prepared to be launched in parallel. Now, the parallel mark threads are not launched, even if available, until the client starts a (user) thread (e.g. calls pthread_create or GC_allow_register_threads) or tells the collector explicitly to start the mark threads (by calling GC_start_mark_threads). * doc/README.macros (GC_ALWAYS_MULTITHREADED): Update documentation. * doc/scale.md (Options for enhanced scalability): Likewise. * include/gc/gc.h [GC_THREADS] (GC_parallel, GC_allow_register_threads): Update comment. * include/gc/gc.h (GC_set_markers_count, GC_start_mark_threads): Likewise. * include/gc/gc_mark.h (GC_mark_proc): Likewise. * include/gc/gc_mark.h (GC_PROC_BYTES, GC_ms_entry): Move upper to be before the comment belonging to GC_mark_proc. * misc.c [THREADS && PARALLEL_MARK] (GC_init): Do not call GC_start_mark_threads_inner(). * misc.c [PARALLEL_MARK] (GC_start_mark_threads): Call GC_start_mark_threads_inner() even if THREAD_SANITIZER or no CAN_HANDLE_FORK. * misc.c [THREADS] (GC_get_parallel): Remove comment. * pthread_support.c [PARALLEL_MARK && !CAN_HANDLE_FORK] (available_markers_m1): Define as a variable. * win32_threads.c [PARALLEL_MARK && !CAN_HANDLE_FORK] (available_markers_m1): Likewise. * pthread_support.c [PARALLEL_MARK && !CAN_HANDLE_FORK] (GC_wait_for_gc_completion): Declare. * pthread_support.c [PARALLEL_MARK && !CAN_HANDLE_FORK] (GC_start_mark_threads_inner): If GC_parallel then return; call GC_wait_for_gc_completion(); set GC_markers_m1 value from available_markers_m1. * win32_threads.c [PARALLEL_MARK && (!GC_PTHREADS_PARAMARK || !CAN_HANDLE_FORK)] (GC_start_mark_threads_inner): Likewise. * pthread_support.c [CAN_HANDLE_FORK && PARALLEL_MARK && THREAD_SANITIZER] (fork_child_proc): Set available_markers_m1 to 0. * pthread_support.c [CAN_HANDLE_FORK]: Move GC_remove_all_threads_but_me() call to be after setting available_markers_m1. * pthread_support.c (GC_allow_register_threads): Call GC_start_mark_threads(). * tests/middle.c (main): Likewise. * win32_threads.c (GC_allow_register_threads): Likewise. * pthread_support.c [PARALLEL_MARK] (pthread_create): Call GC_start_mark_threads() unless GC_parallel or available_markers_m1<=0. * win32_threads.c (START_MARK_THREADS): Define macro (to call GC_start_mark_threads() if PARALLEL_MARK). * win32_threads.c (GC_CreateThread): Call START_MARK_THREADS() (right before set_need_to_lock). * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise.
* Call GC_init_parallel only from GC_initIvan Maidanski2022-05-311-41/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * darwin_stop_world.c [!GC_NO_THREADS_DISCOVERY && !DARWIN_DONT_PARSE_STACK] (GC_use_threads_discovery): Call GC_init() instead of GC_init_parallel(). * pthread_support.c (pthread_create): Likewise. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_use_threads_discovery): Likewise. * win32_threads.c (GC_CreateThread): Likewise. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise. * include/private/gc_priv.h [THREADS] (GC_init, GC_init_parallel): Add comment. * misc.c (GC_init): Replace GC_PTHREADS||GC_WIN32_THREADS with THREADS. * misc.c [THREADS] (GC_init): Call GC_init_parallel() even if no parallel marker support or thread-local allocations; update comment. * pthread_support.c (parallel_initialized): Remove. * win32_threads.c (parallel_initialized): Likewise. * pthread_support.c (GC_init_parallel): Update comment; do not use parallel_initialized; do not call GC_init(); * win32_threads.c (GC_init_parallel): Likewise. * pthread_support.c [THREAD_LOCAL_ALLOC] (GC_init_parallel): Declare and use me local variable. * pthread_support.c [THREAD_LOCAL_ALLOC] (GC_init_parallel): Remove assertion that the GC lock is not hold; add assertion that GC_is_initialized is set. * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_init_parallel): Likewise. * pthread_support.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread, GC_start_rtn_prepare_thread): Remove redundant parentheses in GC_init_thread_local() argument. * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread): Likewise. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_use_threads_discovery): Check GC_is_initialized value instead of parallel_initialized one. * win32_threads.c (GC_CreateThread): Likewise. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Likewise. * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread_inner): Add comment. * win32_threads.c [!GC_ALWAYS_MULTITHREADED && !PARALLEL_MARK && !GC_NO_THREADS_DISCOVERY] (GC_allow_register_threads): Do not set parallel_initialized. * win32_threads.c (GC_init_parallel): Call set_need_to_lock() after GC_init_thread_local().
* Refine comments in code regarding DllMain-based threads registrationIvan Maidanski2022-05-301-3/+5
| | | | | | | | | | | * include/gc/gc.h (GC_use_threads_discovery): Refine comment (mention GC_register_my_thread and GC_init). * os_dep.c [MSWIN32 || MSWINCE] (GC_get_stack_base): Add comment about the GC lock. * win32_threads.c (GC_CreateThread): Add comment about GC_init_parallel if GC_win32_dll_threads set by GC_use_threads_discovery(). * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY] (GC_DllMain): Add more comments for DLL_THREAD_ATTACH case.
* Fix abort in Win32 DllMain if PARALLEL_MARKIvan Maidanski2022-05-301-4/+0
| | | | | | | | | | | | | | (fix of commit f1b257a66) Also, enable GC_use_threads_discovery() on Windows even in case of PARALLEL_MARK. * tests/gctest.c [GC_WIN32_THREADS && !GC_PTHREADS && GC_DLL && !GC_NO_THREADS_DISCOVERY && !MSWINCE && !THREAD_LOCAL_ALLOC] (WinMain): Call GC_use_threads_discovery() regardless of PARALLEL_MARK. * win32_threads.c [!GC_PTHREADS && !GC_NO_THREADS_DISCOVERY && PARALLEL_MARK] (GC_DllMain): Do not abort if DLL_PROCESS_ATTACH or DLL_THREAD_ATTACH (call GC_register_my_thread_inner instead).
* Do not assert that GC is initialized at DLL_THREAD_DETACH (Win32)Ivan Maidanski2022-05-301-1/+0
| | | | | | | | | | (fix of commits 3d7e4a8c6, 1175c7e62) This is to match DLL_THREAD_ATTACH case if parallel_initialized is false. * win32_threads.c [!GC_NO_THREADS_DISCOVERY && !GC_PTHREADS] (GC_DllMain): Remove assertion that parallel_initialized is set (i.e. for the case when GC_win32_dll_threads is set).
* Specify that error conditions are unlikely to be true in threads codeIvan Maidanski2022-05-291-44/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (refactoring) * pthread_support.c [GC_USE_DLOPEN_WRAP] (GC_init_real_syms): Assert that GC_syms_initialized is set. * pthread_support.c [HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG || HAVE_PTHREAD_SETNAME_NP_WITH_TID] (set_marker_thread_name): Use EXPECT(). * pthread_support.c (GC_new_thread, GC_delete_thread, GC_register_altstack, GC_register_my_thread, pthread_create, GC_lock): Likewise. * pthread_support.c [!GC_NO_PTHREAD_SIGMASK] (pthread_sigmask): Likewise. * pthread_support.c [!SN_TARGET_ORBIS && !SN_TARGET_PSP2] (pthread_join, pthread_detach): Likewise. * pthread_support.c [!USE_SPIN_LOCK && !NO_PTHREAD_TRYLOCK || PARALLEL_MARK] (GC_generic_lock): Likewise. * win32_threads.c (GC_new_thread, GC_get_max_thread_index, GC_delete_thread, GC_register_my_thread, GC_CreateThread): Likewise. * win32_threads.c [!GC_NO_THREADS_DISCOVERY] (GC_register_my_thread_inner): Likewise. * win32_threads.c [PARALLEL_MARK] (GC_start_mark_threads_inner, GC_acquire_mark_lock, GC_release_mark_lock): Likewise. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT] (GC_beginthreadex): Likewise. * win32_threads.c [GC_PTHREADS] (pthread_join, GC_pthread_create, GC_pthread_detach): Likewise. * pthread_support.c (GC_new_thread): Change !EXPECT(cond,TRUE) to EXPECT(!cond,FALSE). * win32_threads.c (GC_new_thread): Likewise. * pthread_support.c (GC_register_my_thread): Remove duplicated code related to GC_SUCCESS. * win32_threads.c (GC_register_my_thread): Likewise.
* Update copyright information in alloc.c and other modified files (2022)Ivan Maidanski2022-05-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * CMakeLists.txt: Update year in copyright comment (2021 to 2022). * alloc.c: Likewise. * configure.ac: Likewise. * dyn_load.c: Likewise. * include/private/gc_priv.h: Likewise. * include/private/gcconfig.h: Likewise. * mallocx.c: Likewise. * mark.c: Likewise. * mark_rts.c: Likewise. * misc.c: Likewise. * os_dep.c: Likewise. * pthread_support.c: Likewise. * reclaim.c: Likewise. * tests/gctest.c: Likewise. * win32_threads.c: Likewise. * LICENSE: Update year (2021 to 2022). * allchblk.c: Add copyright line in header comment. * darwin_stop_world.c: Likewise. * dbg_mlc.c: Likewise. * gcj_mlc.c: Likewise. * headers.c: Likewise. * include/gc/gc_inline.h: Likewise. * include/gc/gc_mark.h: Likewise. * include/private/gc_locks.h: Likewise. * include/private/gc_pmark.h: Likewise. * include/private/pthread_stop_world.h: Likewise. * include/private/pthread_support.h: Likewise. * mach_dep.c: Likewise. * malloc.c: Likewise. * thread_local_alloc.c: Likewise. * typd_mlc.c: Likewise. * finalize.c: Update year in copyright comment (2020 to 2022). * include/gc/gc.h: Likewise. * pthread_stop_world.c: Likewise.
* Fix assertion violation in GC_allow_register_threads on WindowsIvan Maidanski2022-05-251-2/+8
| | | | | | | | | (fix of commit ab93e03de) * pthread_support.c [GC_ASSERTIONS] (GC_allow_register_threads): Wrap GC_lookup_thread() call into LOCK/UNLOCK. * win32_threads.c [GC_ASSERTIONS] (GC_allow_register_threads): Wrap GC_lookup_thread_inner() call into LOCK/UNLOCK.
* Ensure GC is initialized when GC_push_all_stacks() is calledIvan Maidanski2022-05-251-11/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* Remove useless TSan W/A about read of mark_lock_holder for WindowsIvan Maidanski2022-05-231-4/+2
| | | | | | | | | | (fix of commit 0fbe44656) TSan itself is not supported on Windows (native and Cygwin) yet. * win32_threads.c [PARALLEL_MARK && (!GC_PTHREADS_PARAMARK || NUMERIC_THREAD_ID_UNIQUE)] (GC_acquire_mark_lock): Assertion about GC_mark_lock_holder regardless of THREAD_SANITIZER.
* Define GC_get_parallel and GC_set_markers_count in single-threaded GCIvan Maidanski2022-05-201-8/+6
| | | | | | | | | | | | | | | | | | These are no-op definitions in case of the collector is built as a single-threaded one. This is useful for single threaded clients to be able to call these functions regardless of the collector is multi-threaded or not. * include/gc/gc.h [GC_THREADS] (GC_parallel): Reformat comment. * include/gc/gc.h (GC_get_parallel, GC_set_markers_count): Declare unconditionally. * misc.c [!PARALLEL_MARK] (GC_set_markers_count): Define (as no-op). * misc.c [!THREADS] (GC_get_parallel): Define (return 0). * pthread_support.c (GC_set_markers_count): Define only if PARALLEL_MARK; remove GC_ATTR_UNUSED. * win32_threads.c (GC_set_markers_count): Likewise. * tests/initfromthread.c (main): Call GC_get_suspend_signal() instead of GC_get_parallel().