X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FSingleton.cpp;h=df3cbcb059cdd647061402474bf18e3b81d90651;hb=55c9d0bdae2f6f77233b3f95809c781e470eccd6;hp=8e9cd99b0763138bd8eb7c61819da5c293a61703;hpb=a7d7c07cadb5d5e9d55d5dd97b3e6069afe21245;p=folly.git diff --git a/folly/Singleton.cpp b/folly/Singleton.cpp index 8e9cd99b..df3cbcb0 100644 --- a/folly/Singleton.cpp +++ b/folly/Singleton.cpp @@ -17,16 +17,29 @@ #include #include +#include +#include +#include #include +#include #include namespace folly { namespace detail { -constexpr std::chrono::seconds SingletonHolderBase::kDestroyWaitTime; - +[[noreturn]] void singletonWarnDoubleRegistrationAndAbort( + const TypeDescriptor& type) { + // Not using LOG(FATAL) or std::cerr because they may not be initialized yet. + std::ostringstream o; + o << "Double registration of singletons of the same " + << "underlying type; check for multiple definitions " + << "of type folly::Singleton<" << type.name() << ">" << std::endl; + auto s = o.str(); + writeFull(STDERR_FILENO, s.data(), s.size()); + std::abort(); +} } namespace { @@ -65,8 +78,7 @@ void SingletonVault::registerSingleton(detail::SingletonHolderBase* entry) { stateCheck(SingletonVaultState::Running); if (UNLIKELY(registrationComplete_)) { - throw std::logic_error( - "Registering singleton after registrationComplete()."); + LOG(ERROR) << "Registering singleton after registrationComplete()."; } RWSpinLock::ReadHolder rhMutex(&mutex_); @@ -83,8 +95,7 @@ void SingletonVault::addEagerInitSingleton(detail::SingletonHolderBase* entry) { stateCheck(SingletonVaultState::Running); if (UNLIKELY(registrationComplete_)) { - throw std::logic_error( - "Registering for eager-load after registrationComplete()."); + LOG(ERROR) << "Registering for eager-load after registrationComplete()."; } RWSpinLock::ReadHolder rhMutex(&mutex_);