From: ivmai Date: Fri, 22 Apr 2011 11:54:12 +0000 (+0000) Subject: 2011-04-22 Ivan Maidanski X-Git-Tag: gc7_2alpha6~56 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=583e58963af8a38848e91d5fab2039e42d6cb911;p=gc 2011-04-22 Ivan Maidanski * os_dep.c (GC_get_stack_base): Implement for Android (same as for Linux). * pthread_support.c (GC_get_nprocs): Return 1 (instead of -1) if failed to open "stat" file (not to issue a warning twice); update the comment. * pthread_support.c (GC_thr_init): Call sysconf() on Android to get the number of CPUs. --- diff --git a/ChangeLog b/ChangeLog index 80f1b0cd..b57c19e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-04-22 Ivan Maidanski + + * os_dep.c (GC_get_stack_base): Implement for Android (same as + for Linux). + * pthread_support.c (GC_get_nprocs): Return 1 (instead of -1) if + failed to open "stat" file (not to issue a warning twice); update + the comment. + * pthread_support.c (GC_thr_init): Call sysconf() on Android to + get the number of CPUs. + 2011-04-21 Ivan Maidanski * include/private/gc_priv.h (_GNU_SOURCE): Revert one of the diff --git a/os_dep.c b/os_dep.c index 75f9c7a7..a562b79c 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1222,7 +1222,7 @@ GC_INNER word GC_page_size = 0; } #endif /* !AMIGA, !BEOS, !OPENBSD, !OS2, !Windows */ -#if defined(GC_LINUX_THREADS) && !defined(NACL) +#if (defined(GC_LINUX_THREADS) || defined(PLATFORM_ANDROID)) && !defined(NACL) # include /* extern int pthread_getattr_np(pthread_t, pthread_attr_t *); */ diff --git a/pthread_support.c b/pthread_support.c index 0f1d9242..16d0dc9a 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -708,7 +708,7 @@ STATIC void GC_remove_all_threads_but_me(void) #endif /* IA64 */ #if defined(GC_LINUX_THREADS) && !defined(NACL) - /* Return the number of processors, or i<= 0 if it can't be determined. */ + /* Return the number of processors. */ STATIC int GC_get_nprocs(void) { /* Should be "return sysconf(_SC_NPROCESSORS_ONLN);" but that */ @@ -732,16 +732,18 @@ STATIC void GC_remove_all_threads_but_me(void) f = open("/proc/stat", O_RDONLY); if (f < 0 || (len = STAT_READ(f, stat_buf, STAT_BUF_SIZE)) < 100) { WARN("Couldn't read /proc/stat\n", 0); - return -1; + return 1; /* assume an uniprocessor */ } + close(f); + for (i = 0; i < len - 100; ++i) { if (stat_buf[i] == '\n' && stat_buf[i+1] == 'c' && stat_buf[i+2] == 'p' && stat_buf[i+3] == 'u') { - int cpu_no = atoi(stat_buf + i + 4); - if (cpu_no >= result) result = cpu_no + 1; + int cpu_no = atoi(&stat_buf[i + 4]); + if (cpu_no >= result) + result = cpu_no + 1; } } - close(f); return result; } #endif /* GC_LINUX_THREADS && !NACL */ @@ -849,7 +851,7 @@ STATIC void GC_fork_child_proc(void) /* */ int numCpus; struct dg_sys_info_pm_info pm_sysinfo; - int status =0; + int status = 0; status = dg_sys_info((long int *) &pm_sysinfo, DG_SYS_INFO_PM_INFO_TYPE, DG_SYS_INFO_PM_CURRENT_VERSION); @@ -945,7 +947,7 @@ GC_INNER void GC_thr_init(void) GC_nprocs = pthread_num_processors_np(); # elif defined(GC_OSF1_THREADS) || defined(GC_AIX_THREADS) \ || defined(GC_SOLARIS_THREADS) || defined(GC_GNU_THREADS) \ - || defined(NACL) + || defined(PLATFORM_ANDROID) || defined(NACL) GC_nprocs = sysconf(_SC_NPROCESSORS_ONLN); if (GC_nprocs <= 0) GC_nprocs = 1; # elif defined(GC_IRIX_THREADS) @@ -960,7 +962,7 @@ GC_INNER void GC_thr_init(void) } if (GC_nprocs <= 0) { WARN("GC_get_nprocs() returned %" GC_PRIdPTR "\n", GC_nprocs); - GC_nprocs = 2; + GC_nprocs = 2; /* assume dual-core */ # ifdef PARALLEL_MARK GC_markers = 1; # endif @@ -1844,4 +1846,4 @@ GC_INNER void GC_notify_all_marker(void) #endif /* PARALLEL_MARK */ -#endif /* GC_LINUX_THREADS and friends */ +#endif /* GC_PTHREADS */