summaryrefslogtreecommitdiff
path: root/win32_threads.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2020-08-13 16:49:03 +0300
committerIvan Maidanski <ivmai@mail.ru>2020-08-13 16:49:03 +0300
commitee900ca80085032156573517998c6cbfa1494377 (patch)
tree49be4fcf55373bfb8603f8b751564d3dab7a8ba7 /win32_threads.c
parent1465f95018cacd77a1654f4a07ed2c051b1da821 (diff)
downloadbdwgc-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 'win32_threads.c')
-rw-r--r--win32_threads.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/win32_threads.c b/win32_threads.c
index 72406d92..ee2222b0 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -2500,6 +2500,9 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
# endif /* ! GC_PTHREADS_PARAMARK */
+ static unsigned required_markers_cnt = 0;
+ /* The default value (0) means the number of */
+ /* markers should be selected automatically. */
#endif /* PARALLEL_MARK */
/* We have no DllMain to take care of new threads. Thus we */
@@ -2737,6 +2740,14 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
#endif /* GC_WINMAIN_REDIRECT */
+GC_API void GC_CALL GC_set_markers_count(unsigned markers GC_ATTR_UNUSED)
+{
+ /* The same implementation as in pthread_support.c. */
+# ifdef PARALLEL_MARK
+ required_markers_cnt = markers < MAX_MARKERS ? markers : MAX_MARKERS;
+# endif
+}
+
GC_INNER void GC_thr_init(void)
{
struct GC_stack_base sb;
@@ -2792,7 +2803,7 @@ GC_INNER void GC_thr_init(void)
# if defined(PARALLEL_MARK)
{
char * markers_string = GETENV("GC_MARKERS");
- int markers;
+ int markers = required_markers_cnt;
if (markers_string != NULL) {
markers = atoi(markers_string);
@@ -2801,7 +2812,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. */
# ifdef MSWINCE
/* There is no GetProcessAffinityMask() in WinCE. */
/* GC_sysinfo is already initialized. */