Commit 563a1bfc authored by tqcq's avatar tqcq
Browse files

feat add __attribute__((construcotr))

parent fc1ad57b
Loading
Loading
Loading
Loading
+29 −29
Original line number Diff line number Diff line
@@ -39,18 +39,21 @@
class GoogleInitializer {
public:
    typedef void (*VoidFunction)(void);
  GoogleInitializer(const char* name, VoidFunction ctor, VoidFunction dtor)
      : name_(name), destructor_(dtor) {

    GoogleInitializer(const char *name, VoidFunction ctor, VoidFunction dtor) : name_(name), destructor_(dtor)
    {
        RAW_VLOG(10, "<GoogleModuleObject> constructing: %s\n", name_);
    if (ctor)
      ctor();
        if (ctor) ctor();
    }
  ~GoogleInitializer() {

    ~GoogleInitializer()
    {
        RAW_VLOG(10, "<GoogleModuleObject> destroying: %s\n", name_);
    if (destructor_)
      destructor_();
        if (destructor_) destructor_();
    }

    const char *name() const { return name_; }

private:
    const char *const name_;
    const VoidFunction destructor_;
@@ -58,17 +61,14 @@ class GoogleInitializer {

#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);                   \
    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 () { body; }      \
    GoogleInitializer google_destructor_module_##name(#name,    \
            NULL, google_destruct_module_##name);               \
    static void google_destruct_module_##name() __attribute__((constructor)) { body; }                                 \
    GoogleInitializer google_destructor_module_##name(#name, NULL, google_destruct_module_##name);                     \
    }


#endif /* _GOOGLEINIT_H */
+7 −8
Original line number Diff line number Diff line
@@ -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()