X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FSingleton.cpp;h=4f24328e9b2a13f4ab1b03f018933a4afbf386a2;hp=67e6fd811cab7bac48635c1d628a53826df45ac4;hb=7d0d018f7661e1994c7f68c8b80483d80a96f9fd;hpb=0fdbb3df4230829df93437f2143384c6aa27befb diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 67e6fd81..4f24328e 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__) +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__) + 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(