From 010a90ec82fab64072b5c46127ad6b439eac8bfb Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 28 Jan 2012 13:17:51 +0400 Subject: [PATCH] Change GC_markers and GC_nprocs type to int * include/private/gc_priv.h (GC_markers): Change type from long to int. * mark.c (GC_markers): Likewise. * pthread_support.c (GC_nprocs): Likewise. * pthread_support.c (start_mark_threads, GC_thr_init): Adjust printf format specifier for GC_markers and GC_nprocs. * win32_threads.c (GC_thr_init): Likewise. * pthread_support.c (GC_thr_init): Cast sysconf() result to int. * win32_threads.c (start_mark_threads, GC_wait_marker, GC_notify_all_marker): Remove unnecessary cast of GC_markers. * win32_threads.c (GC_thr_init): Cast dwNumberOfProcessors to int. --- include/private/gc_priv.h | 2 +- mark.c | 3 ++- pthread_support.c | 12 ++++++------ win32_threads.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index ada5b3e..fed7f2b 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -2203,7 +2203,7 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str, /* than the main garbage collector lock; standard pthreads-based */ /* implementations should be sufficient. */ - GC_EXTERN long GC_markers; /* Number of mark threads we would like */ + GC_EXTERN int GC_markers; /* Number of mark threads we would like */ /* to have. Includes the initiating */ /* thread. Defined in mark.c. */ diff --git a/mark.c b/mark.c index 1e58424..f419736 100644 --- a/mark.c +++ b/mark.c @@ -1017,7 +1017,7 @@ STATIC void GC_do_local_mark(mse *local_mark_stack, mse *local_top) #define ENTRIES_TO_GET 5 -GC_INNER long GC_markers = 2; /* Normally changed by thread-library- */ +GC_INNER int GC_markers = 2; /* Normally changed by thread-library- */ /* -specific code. */ /* Mark using the local mark stack until the global mark stack is empty */ @@ -1172,6 +1172,7 @@ GC_INNER void GC_help_marker(word my_mark_no) unsigned my_id; if (!GC_parallel) return; + GC_acquire_mark_lock(); while (GC_mark_no < my_mark_no || (!GC_help_wanted && GC_mark_no == my_mark_no)) { diff --git a/pthread_support.c b/pthread_support.c index 218b662..99c0123 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -274,7 +274,7 @@ static GC_bool parallel_initialized = FALSE; GC_INNER GC_bool GC_need_to_lock = FALSE; -STATIC long GC_nprocs = 1; +STATIC int GC_nprocs = 1; /* Number of processors. We may not have */ /* access to all of them, but this is as good */ /* a guess as any ... */ @@ -432,7 +432,7 @@ static void start_mark_threads(void) } } if (GC_print_stats) { - GC_log_printf("Started %ld mark helper threads\n", GC_markers - 1); + GC_log_printf("Started %d mark helper threads\n", GC_markers - 1); } pthread_attr_destroy(&attr); } @@ -1018,10 +1018,10 @@ GC_INNER void GC_thr_init(void) # elif defined(GC_OSF1_THREADS) || defined(GC_AIX_THREADS) \ || defined(GC_SOLARIS_THREADS) || defined(GC_GNU_THREADS) \ || defined(PLATFORM_ANDROID) || defined(NACL) - GC_nprocs = sysconf(_SC_NPROCESSORS_ONLN); + GC_nprocs = (int)sysconf(_SC_NPROCESSORS_ONLN); if (GC_nprocs <= 0) GC_nprocs = 1; # elif defined(GC_IRIX_THREADS) - GC_nprocs = sysconf(_SC_NPROC_ONLN); + GC_nprocs = (int)sysconf(_SC_NPROC_ONLN); if (GC_nprocs <= 0) GC_nprocs = 1; # elif defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS) \ || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS) @@ -1064,8 +1064,8 @@ GC_INNER void GC_thr_init(void) # ifdef PARALLEL_MARK if (GC_print_stats) { GC_log_printf( - "Number of processors = %ld, number of marker threads = %ld\n", - GC_nprocs, GC_markers); + "Number of processors = %d, number of marker threads = %d\n", + GC_nprocs, GC_markers); } if (GC_markers <= 1) { GC_parallel = FALSE; diff --git a/win32_threads.c b/win32_threads.c index a6329ea..257f049 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1780,9 +1780,9 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, /* Adjust GC_markers (and free unused resources) in case of failure. */ # ifdef DONT_USE_SIGNALANDWAIT - while ((int)GC_markers > i + 1) { + while (GC_markers > i + 1) { GC_markers--; - CloseHandle(GC_marker_cv[(int)GC_markers - 1]); + CloseHandle(GC_marker_cv[GC_markers - 1]); } # else GC_markers = i + 1; @@ -1904,7 +1904,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, { HANDLE event = mark_cv; DWORD thread_id = GetCurrentThreadId(); - int i = (int)GC_markers - 1; + int i = GC_markers - 1; while (i-- > 0) { if (GC_marker_Id[i] == thread_id) { event = GC_marker_cv[i]; @@ -1923,7 +1923,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_INNER void GC_notify_all_marker(void) { DWORD thread_id = GetCurrentThreadId(); - int i = (int)GC_markers - 1; + int i = GC_markers - 1; while (i-- > 0) { /* Notify every marker ignoring self (for efficiency). */ if (SetEvent(GC_marker_Id[i] != thread_id ? GC_marker_cv[i] : @@ -2280,7 +2280,7 @@ GC_INNER void GC_thr_init(void) # ifdef MSWINCE /* There is no GetProcessAffinityMask() in WinCE. */ /* GC_sysinfo is already initialized. */ - GC_markers = GC_sysinfo.dwNumberOfProcessors; + GC_markers = (int)GC_sysinfo.dwNumberOfProcessors; # else # ifdef _WIN64 DWORD_PTR procMask = 0; @@ -2357,7 +2357,7 @@ GC_INNER void GC_thr_init(void) /* If we are using a parallel marker, actually start helper threads. */ if (GC_parallel) start_mark_threads(); if (GC_print_stats) { - GC_log_printf("Started %ld mark helper threads\n", GC_markers - 1); + GC_log_printf("Started %d mark helper threads\n", GC_markers - 1); } # endif } -- 2.7.4