diff --git a/3party/gperftools/src/base/googleinit.h b/3party/gperftools/src/base/googleinit.h index a290427..0610e5f 100644 --- a/3party/gperftools/src/base/googleinit.h +++ b/3party/gperftools/src/base/googleinit.h @@ -37,38 +37,38 @@ #include "base/logging.h" class GoogleInitializer { - public: - typedef void (*VoidFunction)(void); - GoogleInitializer(const char* name, VoidFunction ctor, VoidFunction dtor) - : name_(name), destructor_(dtor) { - RAW_VLOG(10, " constructing: %s\n", name_); - if (ctor) - ctor(); - } - ~GoogleInitializer() { - RAW_VLOG(10, " destroying: %s\n", name_); - if (destructor_) - destructor_(); - } +public: + typedef void (*VoidFunction)(void); - private: - const char* const name_; - const VoidFunction destructor_; + GoogleInitializer(const char *name, VoidFunction ctor, VoidFunction dtor) : name_(name), destructor_(dtor) + { + RAW_VLOG(10, " constructing: %s\n", name_); + if (ctor) ctor(); + } + + ~GoogleInitializer() + { + RAW_VLOG(10, " destroying: %s\n", name_); + if (destructor_) destructor_(); + } + + const char *name() const { return name_; } + +private: + const char *const name_; + const VoidFunction destructor_; }; -#define REGISTER_MODULE_INITIALIZER(name, body) \ - namespace { \ - static void google_init_module_##name () { body; } \ - GoogleInitializer google_initializer_module_##name(#name, \ - google_init_module_##name, NULL); \ - } - -#define REGISTER_MODULE_DESTRUCTOR(name, body) \ - namespace { \ - static void google_destruct_module_##name () { body; } \ - GoogleInitializer google_destructor_module_##name(#name, \ - NULL, google_destruct_module_##name); \ - } +#define REGISTER_MODULE_INITIALIZER(name, body) \ + namespace { \ + static void google_init_module_##name() __attribute__((constructor)) { body; } \ + GoogleInitializer google_initializer_module_##name(#name, google_init_module_##name, NULL); \ + } +#define REGISTER_MODULE_DESTRUCTOR(name, body) \ + namespace { \ + static void google_destruct_module_##name() __attribute__((constructor)) { body; } \ + GoogleInitializer google_destructor_module_##name(#name, NULL, google_destruct_module_##name); \ + } #endif /* _GOOGLEINIT_H */ diff --git a/CMakeLists.txt b/CMakeLists.txt index aa5fc20..4f157a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,9 +30,11 @@ target_include_directories(test_main PUBLIC src/) target_include_directories(benchmark_main PUBLIC src/) add_library(sled STATIC "") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL) +endif() add_subdirectory(3party/minilua EXCLUDE_FROM_ALL) -add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL) add_subdirectory(3party/asyncplusplus EXCLUDE_FROM_ALL) # add_subdirectory(3party/cppuprofile EXCLUDE_FROM_ALL) if(SLED_WITH_PROTOBUF) @@ -104,15 +106,12 @@ target_sources( target_link_libraries( sled - PUBLIC rpc_core - fmt - marl - Async++ - minilua - protobuf::libprotobuf - tcmalloc_and_profiler_static + PUBLIC rpc_core fmt marl Async++ minilua protobuf::libprotobuf # protobuf::libprotoc PRIVATE dl) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(sled PRIVATE tcmalloc_and_profiler_static) +endif() if(SLED_WITH_PROTOBUF) target_link_libraries(sled PUBLIC protobuf::libprotobuf) endif()