|
|
@@ -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
|
|
|
}
|