[前][次][番号順一覧][スレッド一覧]

ruby-changes:35682

From: usa <ko1@a...>
Date: Thu, 2 Oct 2014 18:42:29 +0900 (JST)
Subject: [ruby-changes:35682] usa:r47764 (trunk): * ext/etc/etc.c (etc_nprocessors): Windows support.

usa	2014-10-02 18:42:23 +0900 (Thu, 02 Oct 2014)

  New Revision: 47764

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47764

  Log:
    * ext/etc/etc.c (etc_nprocessors): Windows support.
      see [Feature #10267]

  Modified files:
    trunk/ChangeLog
    trunk/ext/etc/etc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47763)
+++ ChangeLog	(revision 47764)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct  2 18:41:45 2014  NAKAMURA Usaku  <usa@r...>
+
+	* ext/etc/etc.c (etc_nprocessors): Windows support.
+	  see [Feature #10267]
+
 Thu Oct  2 12:21:52 2014  Tanaka Akira  <akr@f...>
 
 	* ext/etc/etc.c (etc_nprocessors): New method.
Index: ext/etc/etc.c
===================================================================
--- ext/etc/etc.c	(revision 47763)
+++ ext/etc/etc.c	(revision 47764)
@@ -891,7 +891,7 @@ io_pathconf(VALUE io, VALUE arg) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L891
 #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) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L912
 {
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]