Browse Source

Merge branch 'dev' of http://github.com/ithewei/libhv into dev

ithewei 5 years ago
parent
commit
8425e6a827
3 changed files with 23 additions and 3 deletions
  1. 1 1
      CMakeLists.txt
  2. 18 0
      base/hsysinfo.h
  3. 4 2
      hexport.h

+ 1 - 1
CMakeLists.txt

@@ -154,7 +154,7 @@ list_source_directories(LIBHV_SRCS ${LIBHV_SRCDIRS})
 
 if(BUILD_SHARED)
     add_library(hv SHARED ${LIBHV_SRCS})
-    target_compile_definitions(hv PRIVATE HV_EXPORTS)
+    target_compile_definitions(hv PRIVATE HV_DYNAMICLIB)
     target_include_directories(hv PRIVATE ${LIBHV_SRCDIRS})
     target_link_libraries(hv ${LIBS})
     install(TARGETS hv LIBRARY DESTINATION lib)

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

+ 4 - 2
hexport.h

@@ -5,7 +5,7 @@
 #if defined(HV_STATICLIB) || defined(HV_SOURCE)
     #define HV_EXPORT
 #elif defined(_MSC_VER)
-    #if defined(HV_EXPORTS) || defined(hv_EXPORTS)
+    #if defined(HV_DYNAMICLIB) || defined(HV_EXPORTS) || defined(hv_EXPORTS)
         #define HV_EXPORT  __declspec(dllexport)
     #else
         #define HV_EXPORT  __declspec(dllimport)
@@ -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]