X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FSingleton.cpp;h=7114d53de9df1ca16c630913636a4dc6436e1ddf;hp=67e6fd811cab7bac48635c1d628a53826df45ac4;hb=48d3f5e1691033d00ecc2ef0c3ced83ce148705a;hpb=ed8c80a0e0988e4ce687f51ca832a00e4a6b7930 diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 67e6fd81..7114d53d 100644 --- a/folly/Singleton.cpp +++ b/folly/Singleton.cpp @@ -16,6 +16,10 @@ #include +#ifndef _WIN32 +#include +#endif + #include #include #include @@ -24,8 +28,26 @@ #include +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) +static void hs_init_weak(int* argc, char** argv[]) + __attribute__((__weakref__("hs_init"))); +#endif + namespace folly { +SingletonVault::Type SingletonVault::defaultVaultType() { +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) + bool isPython = dlsym(RTLD_DEFAULT, "Py_Main"); + bool isHaskel = &::hs_init_weak || dlsym(RTLD_DEFAULT, "hs_init"); + bool isJVM = dlsym(RTLD_DEFAULT, "JNI_GetCreatedJavaVMs"); + bool isD = dlsym(RTLD_DEFAULT, "_d_run_main"); + + return isPython || isHaskel || isJVM || isD ? Type::Relaxed : Type::Strict; +#else + return Type::Relaxed; +#endif +} + namespace detail { [[noreturn]] void singletonWarnDoubleRegistrationAndAbort( @@ -38,7 +60,7 @@ namespace detail { << type.name() << ">\n"; std::abort(); } -} +} // namespace detail namespace { @@ -66,7 +88,7 @@ FatalHelper fatalHelper; FatalHelper __attribute__ ((__init_priority__ (101))) fatalHelper; #endif -} +} // namespace SingletonVault::~SingletonVault() { destroyInstances(); } @@ -244,4 +266,4 @@ void SingletonVault::scheduleDestroyInstances() { static SingletonVaultDestructor singletonVaultDestructor; } -} +} // namespace folly