You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/03/23 00:12:17 UTC

svn commit: r1460046 - /incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Author: vinodkone
Date: Fri Mar 22 23:12:16 2013
New Revision: 1460046

URL: http://svn.apache.org/r1460046
Log:
Fixed os::cpus and made os::memory work for OSX.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/9793

Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp?rev=1460046&r1=1460045&r2=1460046&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp Fri Mar 22 23:12:16 2013
@@ -23,6 +23,9 @@
 
 #include <sys/stat.h>
 #include <sys/statvfs.h>
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
 #ifdef __linux__
 #include <sys/sysinfo.h>
 #endif
@@ -891,7 +894,12 @@ inline Try<std::list<std::string> > glob
 // Returns the total number of cpus (cores).
 inline Try<long> cpus()
 {
-  return sysconf(_SC_NPROCESSORS_ONLN);
+  long cpus = sysconf(_SC_NPROCESSORS_ONLN);
+
+  if (cpus < 0) {
+    return ErrnoError();
+  }
+  return cpus;
 }
 
 
@@ -908,6 +916,19 @@ inline Try<uint64_t> memory()
 # else
   return info.totalram;
 # endif
+#elif defined __APPLE__
+  const size_t NAME_SIZE = 2;
+  int name[NAME_SIZE];
+  name[0] = CTL_HW;
+  name[1] = HW_MEMSIZE;
+
+  int64_t memory;
+  size_t length = sizeof(memory);
+
+  if (sysctl(name, NAME_SIZE, &memory, &length, NULL, 0) < 0) {
+    return ErrnoError("Failed to get sysctl of HW_MEMSIZE");
+  }
+  return memory;
 #else
   return Error("Cannot determine the size of main memory");
 #endif