namespace folly {
-namespace {
+namespace detail {
-static constexpr std::chrono::seconds kDestroyWaitTime{5};
+constexpr std::chrono::seconds SingletonHolderBase::kDestroyWaitTime;
}
for (auto type_iter = creation_order_.rbegin();
type_iter != creation_order_.rend();
++type_iter) {
- destroyInstance(singletons_.find(*type_iter));
+ singletons_[*type_iter]->destroyInstance();
}
}
}
}
-/* Destroy and clean-up one singleton. Must be invoked while holding
- * a read lock on mutex_.
- * @param typeDescriptor - the type key for the removed singleton.
- */
-void SingletonVault::destroyInstance(SingletonMap::iterator entry_it) {
- const auto& type = entry_it->first;
- auto& entry = *(entry_it->second);
-
- entry.state = detail::SingletonEntryState::Dead;
- entry.instance.reset();
- auto wait_result = entry.destroy_baton->timed_wait(
- std::chrono::steady_clock::now() + kDestroyWaitTime);
- if (!wait_result) {
- LOG(ERROR) << "Singleton of type " << type.prettyName() << " has a living "
- << "reference at destroyInstances time; beware! Raw pointer "
- << "is " << entry.instance_ptr << ". It is very likely that "
- << "some other singleton is holding a shared_ptr to it. Make "
- << "sure dependencies between these singletons are properly "
- << "defined.";
- }
-}
-
void SingletonVault::reenableInstances() {
RWSpinLock::WriteHolder state_wh(&stateMutex_);