From 92741bb2c9ff09bce7ff8b6c7c7788acc1de331e Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 28 Jul 2018 00:29:59 +0300 Subject: [PATCH] Export stop/start_world_external only for multi-threaded builds (fix of commit bb91f03) Issue #173 (bdwgc). Also, update GC_world_stopped value in GC_stop_world_external and GC_start_world_external. * include/gc.h (GC_stop_world_external, GC_start_world_external): Do not declare unless GC_THREADS; add comment. * misc.c (GC_stop_world_external, GC_start_world_external): Do not define unless THREADS; add assertion that GC is initialized. * misc.c [THREADS && THREAD_LOCAL_ALLOC] (GC_stop_world_external): Set GC_world_stopped to true after STOP_WORLD; add assertion that the world is not stopped. * misc.c [THREADS && THREAD_LOCAL_ALLOC] (GC_start_world_external): Set GC_world_stopped to false before START_WORLD; add assertion that the world is stopped. * tests/test.c [GC_PTHREADS && CPPCHECK] (main): Add UNTESTED for GC_stop_world_external and GC_start_world_external. --- include/gc.h | 7 ++++--- misc.c | 27 +++++++++++++++++++++------ tests/test.c | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/gc.h b/include/gc.h index 0a4ee50..b8b0692 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1503,6 +1503,10 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */, /* be called inside a GC callback function (except for */ /* GC_call_with_stack_base() one). */ GC_API int GC_CALL GC_unregister_my_thread(void); + + /* Stop/start the world explicitly. Not recommended for general use. */ + GC_API void GC_CALL GC_stop_world_external(void); + GC_API void GC_CALL GC_start_world_external(void); #endif /* GC_THREADS */ /* Wrapper for functions that are likely to block (or, at least, do not */ @@ -2042,9 +2046,6 @@ GC_API void GC_CALL GC_win32_free_heap(void); (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page) #endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */ -GC_API void GC_CALL GC_stop_world_external(void); -GC_API void GC_CALL GC_start_world_external(void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/misc.c b/misc.c index a597a0a..6bfa4a1 100644 --- a/misc.c +++ b/misc.c @@ -2529,14 +2529,29 @@ GC_API void GC_CALL GC_abort_on_oom(void) EXIT(); } -GC_API void GC_CALL GC_stop_world_external(void) -{ +#ifdef THREADS + GC_API void GC_CALL GC_stop_world_external(void) + { + GC_ASSERT(GC_is_initialized); LOCK(); +# ifdef THREAD_LOCAL_ALLOC + GC_ASSERT(!GC_world_stopped); +# endif STOP_WORLD(); -} +# ifdef THREAD_LOCAL_ALLOC + GC_world_stopped = TRUE; +# endif + } -GC_API void GC_CALL GC_start_world_external(void) -{ + GC_API void GC_CALL GC_start_world_external(void) + { +# ifdef THREAD_LOCAL_ALLOC + GC_ASSERT(GC_world_stopped); + GC_world_stopped = FALSE; +# else + GC_ASSERT(GC_is_initialized); +# endif START_WORLD(); UNLOCK(); -} + } +#endif /* THREADS */ diff --git a/tests/test.c b/tests/test.c index efce7f4..17f61d3 100644 --- a/tests/test.c +++ b/tests/test.c @@ -2340,6 +2340,8 @@ int main(void) UNTESTED(GC_set_on_thread_event); UNTESTED(GC_set_suspend_signal); UNTESTED(GC_set_thr_restart_signal); + UNTESTED(GC_stop_world_external); + UNTESTED(GC_start_world_external); # ifndef GC_NO_DLOPEN UNTESTED(GC_dlopen); # endif -- 2.7.4