mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vinodk...@apache.org
Subject svn commit: r1460046 - /incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
Date Fri, 22 Mar 2013 23:12:17 GMT
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 <benjamin.mahler@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



Mime
View raw message