diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/etc/etc.c | 8 |
2 files changed, 12 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Thu Oct 2 18:41:45 2014 NAKAMURA Usaku <usa@ruby-lang.org> + + * ext/etc/etc.c (etc_nprocessors): Windows support. + see [Feature #10267] + Thu Oct 2 12:21:52 2014 Tanaka Akira <akr@fsij.org> * ext/etc/etc.c (etc_nprocessors): New method. diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 2546560713..02f8091b4c 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -891,7 +891,7 @@ io_pathconf(VALUE io, VALUE arg) #define io_pathconf rb_f_notimplement #endif -#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) +#if (defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)) || defined(_WIN32) /* * Returns the number of online processors. * @@ -912,11 +912,17 @@ etc_nprocessors(VALUE obj) { long ret; +#if !defined(_WIN32) errno = 0; ret = sysconf(_SC_NPROCESSORS_ONLN); if (ret == -1) { rb_sys_fail("sysconf(_SC_NPROCESSORS_ONLN)"); } +#else + SYSTEM_INFO si; + GetSystemInfo(&si); + ret = (long)si.dwNumberOfProcessors; +#endif return LONG2NUM(ret); } #else |