]> granicus.if.org Git - gc/commitdiff
Ensure GC initialized when atfork_prepare is called by client
authorIvan Maidanski <ivmai@mail.ru>
Fri, 23 Jun 2017 06:13:15 +0000 (09:13 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 23 Jun 2017 06:13:15 +0000 (09:13 +0300)
Otherwise, if THREAD_LOCAL_ALLOC, GC_remove_all_threads_but_me would
not find the current thread descriptor in GC_threads.

* pthread_support.c [CAN_HANDLE_FORK] (GC_atfork_prepare): Call GC_init
if not GC_is_initialized.
* win32_threads.c [CAN_HANDLE_FORK] (GC_atfork_prepare): Likewise.

pthread_support.c
win32_threads.c

index e406322e6e9687ec01b17335328b7b5c9d144edb..effd850da495477708d094fd169ebf0280fce756 100644 (file)
@@ -1061,6 +1061,7 @@ static void fork_child_proc(void)
   /* Routines for fork handling by client (no-op if pthread_atfork works). */
   GC_API void GC_CALL GC_atfork_prepare(void)
   {
+    if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
 #   if defined(GC_DARWIN_THREADS) && defined(MPROTECT_VDB)
       if (GC_dirty_maintained) {
         GC_ASSERT(0 == GC_handle_fork);
index 55658416e76442fa914a07f806d9069e193ae3ed..ae643ba019d05f39a8e5b8d14f8cd134da6e4bd5 100644 (file)
@@ -1110,6 +1110,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
   /* Routines for fork handling by client (no-op if pthread_atfork works). */
   GC_API void GC_CALL GC_atfork_prepare(void)
   {
+    if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
     if (GC_handle_fork <= 0)
       fork_prepare_proc();
   }