logging: set the thread name for the AsyncFileWriter thread
[folly.git] / folly / Singleton-inl.h
index 40c7a27af3c098d0a0c0e9b9f11b4c873cb1a1b4..745147f0454934097e0d7332d6f6ce76c822500a 100644 (file)
@@ -69,7 +69,9 @@ void SingletonHolder<T>::registerSingletonMock(CreateFunc c, TeardownFunc t) {
     LOG(FATAL) << "Registering mock before singleton was registered: "
                << type().name();
   }
-  destroyInstance();
+  if (state_ == SingletonHolderState::Living) {
+    destroyInstance();
+  }
 
   {
     auto creationOrder = vault_.creationOrder_.wlock();
@@ -237,7 +239,11 @@ void SingletonHolder<T>::createInstance() {
     }
 
     LOG(FATAL) << "Singleton " << type().name() << " requested before "
-               << "registrationComplete() call. " << stack_trace;
+               << "registrationComplete() call.\n"
+               << "This usually means that either main() never called "
+               << "folly::init, or singleton was requested before main() "
+               << "(which is not allowed).\n"
+               << stack_trace;
   }
   if (state->state == SingletonVault::SingletonVaultState::Quiescing) {
     return;
@@ -290,6 +296,6 @@ void SingletonHolder<T>::createInstance() {
   vault_.creationOrder_.wlock()->push_back(type());
 }
 
-}
+} // namespace detail
 
-}
+} // namespace folly