X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSingleton.cpp;h=7114d53de9df1ca16c630913636a4dc6436e1ddf;hb=d389a33028d1a8a8520bc5c85dbcf767131fd51c;hp=6a240181cedf13abedb9ad8ab18bf59fdf42af02;hpb=ee43735cc06a4243e6676b332035927715643be7;p=folly.git diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 6a240181..7114d53d 100644 --- a/folly/Singleton.cpp +++ b/folly/Singleton.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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