hewei.it 5 years ago
parent
commit
8f94c6ea3b
2 changed files with 21 additions and 1 deletions
  1. 18 0
      base/hsysinfo.h
  2. 3 1
      hexport.h

+ 18 - 0
base/hsysinfo.h

@@ -7,6 +7,11 @@
 #include <sys/sysinfo.h>
 #endif
 
+#ifdef OS_DARWIN
+#include <mach/mach_host.h>
+#include <sys/sysctl.h>
+#endif
+
 static inline int get_ncpu() {
 #ifdef OS_WIN
     SYSTEM_INFO si;
@@ -42,7 +47,20 @@ static inline int get_meminfo(meminfo_t* mem) {
     mem->total = info.totalram * info.mem_unit >> 10;
     mem->free = info.freeram * info.mem_unit >> 10;
     return 0;
+#elif defined(OS_DARWIN)
+    uint64_t memsize = 0;
+    size_t size = sizeof(memsize);
+    int which[2] = {CTL_HW, HW_MEMSIZE};
+    sysctl(which, 2, &memsize, &size, NULL, 0);
+    mem->total = memsize >> 10;
+
+    vm_statistics_data_t info;
+    mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
+    host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count);
+    mem->free = ((uint64_t)info.free_count * sysconf(_SC_PAGESIZE)) >> 10;
+    return 0;
 #else
+    (void)(mem);
     return -10;
 #endif
 }

+ 3 - 1
hexport.h

@@ -18,9 +18,11 @@
 
 // DEPRECATED
 #if defined(__GNUC__) || defined(__clang__)
-    #define DEPRECATED __attribute__((visibility("deprecated")))
+    #define DEPRECATED  __attribute__((visibility("deprecated")))
+    #define UNUSED      __attribute__((visibility("unused")))
 #else
     #define DEPRECATED
+    #define UNUSED(v)   ((void)(v))
 #endif
 
 // @param[IN | OUT | INOUT]