#include <folly/Singleton.h>
#include <atomic>
+#include <cstdio>
+#include <cstdlib>
+#include <sstream>
#include <string>
+#include <folly/FileUtil.h>
#include <folly/ScopeGuard.h>
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 {
stateCheck(SingletonVaultState::Running);
if (UNLIKELY(registrationComplete_)) {
- throw std::logic_error(
- "Registering singleton after registrationComplete().");
+ LOG(ERROR) << "Registering singleton after registrationComplete().";
}
RWSpinLock::ReadHolder rhMutex(&mutex_);
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_);