summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-02 09:42:23 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-02 09:42:23 +0000
commit56fa18c9d3fc8e817c7bc49cca777b051a8c5ff5 (patch)
tree90f040d676db800331b3f3ac2cf076990b904752 /ext
parentfe18cd011c516a20dc60654e8559f699f54181e2 (diff)
* ext/etc/etc.c (etc_nprocessors): Windows support.
see [Feature #10267] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/etc/etc.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 2546560..02f8091 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