summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-05-20 09:38:01 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-05-20 09:38:01 +0300
commit1b4e5168adb06260bb9c439816a05ddb861dd7e0 (patch)
treeaf8712169fc885496eb122bf1c21db99fa4b037b
parentaf2b607c4ef65f828c5acb8027eada47cf72a5fc (diff)
downloadbdwgc-1b4e5168adb06260bb9c439816a05ddb861dd7e0.tar.gz
Allow to start marker threads in child of single-threaded client
Now GC_start_mark_threads() is present even if the collector is single-threaded (the function does nothing in this case). * include/gc/gc.h (GC_start_mark_threads): Declare unconditionally (i.e. even w/o GC_THREADS). * misc.c (GC_start_mark_threads): Define unconditionally (no-op in case of GC_THREADS is not defined). * tests/gctest.c [!NO_TEST_HANDLE_FORK && !GC_THREADS] (run_one_test): Call GC_start_mark_threads().
-rw-r--r--include/gc/gc.h12
-rw-r--r--misc.c8
-rw-r--r--tests/gctest.c8
3 files changed, 12 insertions, 16 deletions
diff --git a/include/gc/gc.h b/include/gc/gc.h
index 29e967a1..6c643b13 100644
--- a/include/gc/gc.h
+++ b/include/gc/gc.h
@@ -512,7 +512,7 @@ GC_API void GC_CALL GC_set_handle_fork(int);
/* before fork(); GC_atfork_parent should be invoked just after fork in */
/* the branch that corresponds to parent process (i.e., fork result is */
/* non-zero); GC_atfork_child is to be called immediately in the child */
-/* branch (i.e., fork result is 0). Note that GC_atfork_child() call */
+/* branch (i.e., fork result is 0). Note that GC_atfork_child() call */
/* should, of course, precede GC_start_mark_threads call (if any). */
GC_API void GC_CALL GC_atfork_prepare(void);
GC_API void GC_CALL GC_atfork_parent(void);
@@ -1510,6 +1510,11 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */,
#define GC_NOT_FOUND 4 /* Requested link not found (returned */
/* by GC_move_disappearing_link). */
+/* Restart marker threads after POSIX fork in child. Meaningless in */
+/* other situations. Should not be called if fork followed by exec. */
+/* Acquires the GC lock to avoid a data race. */
+GC_API void GC_CALL GC_start_mark_threads(void);
+
#if defined(GC_DARWIN_THREADS) || defined(GC_WIN32_THREADS)
/* Use implicit thread registration and processing (via Win32 DllMain */
/* or Darwin task_threads). Deprecated. Must be called before */
@@ -1538,11 +1543,6 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */,
/* systems. Return -1 otherwise. */
GC_API int GC_CALL GC_get_thr_restart_signal(void);
- /* Restart marker threads after POSIX fork in child. Meaningless in */
- /* other situations. Should not be called if fork followed by exec. */
- /* Acquires the GC lock to avoid a data race. */
- GC_API void GC_CALL GC_start_mark_threads(void);
-
/* Explicitly enable GC_register_my_thread() invocation. */
/* Done implicitly if a GC thread-creation function is called (or */
/* implicit thread registration is activated, or the collector is */
diff --git a/misc.c b/misc.c
index 646dbb31..7f53729d 100644
--- a/misc.c
+++ b/misc.c
@@ -1445,9 +1445,8 @@ GC_API void GC_CALL GC_enable_incremental(void)
GC_init();
}
-#if defined(THREADS)
- GC_API void GC_CALL GC_start_mark_threads(void)
- {
+GC_API void GC_CALL GC_start_mark_threads(void)
+{
# if defined(PARALLEL_MARK) && defined(CAN_HANDLE_FORK) \
&& !defined(THREAD_SANITIZER)
/* TSan does not support threads creation in the child process. */
@@ -1463,8 +1462,7 @@ GC_API void GC_CALL GC_enable_incremental(void)
/* No action since parallel markers are disabled (or no POSIX fork). */
GC_ASSERT(I_DONT_HOLD_LOCK());
# endif
- }
-#endif
+}
GC_API void GC_CALL GC_deinit(void)
{
diff --git a/tests/gctest.c b/tests/gctest.c
index 11235121..717873d2 100644
--- a/tests/gctest.c
+++ b/tests/gctest.c
@@ -1601,12 +1601,10 @@ void run_one_test(void)
if (print_stats)
GC_log_printf("Started a child process, pid= %ld\n",
(long)child_pid);
-# ifdef THREADS
-# ifdef PARALLEL_MARK
- GC_gcollect(); /* no parallel markers */
-# endif
- GC_start_mark_threads();
+# ifdef PARALLEL_MARK
+ GC_gcollect(); /* no parallel markers */
# endif
+ GC_start_mark_threads();
GC_gcollect();
# ifdef THREADS
/* Skip "Premature finalization" check in the */