LOG(FATAL) << "Registering mock before singleton was registered: "
<< type().name();
}
- destroyInstance();
+ if (state_ == SingletonHolderState::Living) {
+ destroyInstance();
+ }
{
auto creationOrder = vault_.creationOrder_.wlock();
instance_copy_.reset();
if (destroy_baton_) {
constexpr std::chrono::seconds kDestroyWaitTime{5};
- auto last_reference_released = destroy_baton_->timed_wait(
- std::chrono::steady_clock::now() + kDestroyWaitTime);
+ auto last_reference_released =
+ destroy_baton_->try_wait_for(kDestroyWaitTime);
if (last_reference_released) {
teardown_(instance_ptr_);
} else {
}
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;
vault_.creationOrder_.wlock()->push_back(type());
}
-}
+} // namespace detail
-}
+} // namespace folly