]> 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>
Tue, 4 Jul 2017 21:57:18 +0000 (00:57 +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 6d66792e0f2906bbff1f0d84603cb287832169ac..e0a874224d5f9931c7763bf15abbd0d98df42e82 100644 (file)
@@ -990,6 +990,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 e64a9fd1f16544c3257c29085e69533d32a728b8..7af26bd75ca2215f43f97fc0e100008f72cc29c1 100644 (file)
@@ -1086,6 +1086,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();
   }