diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2020-08-13 16:49:03 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2020-08-13 16:49:03 +0300 |
commit | ee900ca80085032156573517998c6cbfa1494377 (patch) | |
tree | 49be4fcf55373bfb8603f8b751564d3dab7a8ba7 /pthread_support.c | |
parent | 1465f95018cacd77a1654f4a07ed2c051b1da821 (diff) | |
download | bdwgc-ee900ca80085032156573517998c6cbfa1494377.tar.gz |
New API (GC_set_markers_count) to control number of parallel markers
Issue #320 (bdwgc).
Note that GC_set_markers_count() has effect only if called before GC
initialization. For convenience, alternatively the client could define
GC_MARKERS macro with the appropriate value before include of gc.h.
* doc/README.macros (GC_MARKERS): Document.
* include/gc.h [GC_THREADS] (GC_parallel): Update comment.
* include/gc.h [GC_THREADS] (GC_set_markers_count): New API function
declaration.
* include/gc.h (GC_INIT_CONF_MARKERS): New internal macro (defined to
GC_set_markers_count(GC_MARKERS) if GC_THREADS and GC_MARKERS are
defined).
* include/gc.h (GC_INIT): Call GC_INIT_CONF_MARKERS before GC_init.
* pthread_support.c [PARALLEL_MARK] (required_markers_cnt): New static
variable (initialized to 0).
* win32_threads.c [PARALLEL_MARK] (required_markers_cnt): Likewise.
* pthread_support.c (GC_set_markers_count): New API function definition
(empty unless PARALLEL_MARK).
* win32_threads.c [PARALLEL_MARK] (GC_set_markers_count): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_thr_init): Initialize markers
local variable to required_markers_cnt; set markers to GC_nprocs only
if markers_string is null and required_markers_cnt (markers) value is
zero.
* tests/test.c [GC_PTHREADS] (main): Call GC_set_markers_count(0)
before GC_COND_INIT().
* win32_threads.c [PARALLEL_MARK] (GC_thr_init): Initialize markers
local variable to required_markers_cnt; set markers to ncpu only if
markers_string is null and required_markers_cnt (markers) value is 0.
Diffstat (limited to 'pthread_support.c')
-rw-r--r-- | pthread_support.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/pthread_support.c b/pthread_support.c index 7046a124..dc6041f7 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1219,7 +1219,18 @@ static void fork_child_proc(void) #ifdef PARALLEL_MARK static void setup_mark_lock(void); -#endif + + static unsigned required_markers_cnt = 0; + /* The default value (0) means the number of */ + /* markers should be selected automatically. */ +#endif /* PARALLEL_MARK */ + +GC_API void GC_CALL GC_set_markers_count(unsigned markers GC_ATTR_UNUSED) +{ +# ifdef PARALLEL_MARK + required_markers_cnt = markers < MAX_MARKERS ? markers : MAX_MARKERS; +# endif +} GC_INNER void GC_thr_init(void) { @@ -1309,7 +1320,7 @@ GC_INNER void GC_thr_init(void) # ifdef PARALLEL_MARK { char * markers_string = GETENV("GC_MARKERS"); - int markers; + int markers = required_markers_cnt; if (markers_string != NULL) { markers = atoi(markers_string); @@ -1318,7 +1329,10 @@ GC_INNER void GC_thr_init(void) "; using maximum threads\n", (signed_word)markers); markers = MAX_MARKERS; } - } else { + } else if (0 == markers) { + /* Unless the client sets the desired number of */ + /* parallel markers, it is determined based on the */ + /* number of CPU cores. */ markers = GC_nprocs; # if defined(GC_MIN_MARKERS) && !defined(CPPCHECK) /* This is primarily for targets without getenv(). */ |