]> granicus.if.org Git - gc/commitdiff
Export stop/start_world_external only for multi-threaded builds
authorIvan Maidanski <ivmai@mail.ru>
Fri, 27 Jul 2018 21:29:59 +0000 (00:29 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 27 Jul 2018 21:38:19 +0000 (00:38 +0300)
(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
misc.c
tests/test.c

index 0a4ee500dd89b83ccc81de7c0abb734d217a838e..b8b069269024d4ed55c16737915e6fb71bd00057 100644 (file)
@@ -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 a597a0a7db689f29ce8818a79921cbb8c433acc7..6bfa4a14433dd1257e76d8ae2fb93aa0ae03434f 100644 (file)
--- 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 */
index efce7f42eb0844b9f732bfc7bdb8fa03f8b12e18..17f61d3d76ca3f84651dc5a5b745dc1e8e3b216f 100644 (file)
@@ -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