From c7656e1f39228fe5f78658c1f49c980a8ac597e4 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Fri, 19 Aug 2016 11:55:15 -0700 Subject: [PATCH] Don't allow getting singleton after shutdown in strict mode Summary: Make strict mode stricter, by not allowing singleton to be fetched after shutdown (even with try_get). Reviewed By: yfeldblum Differential Revision: D3737925 fbshipit-source-id: 8d5536c4f27e13feee722b5abeb15db6fe3d77bf --- folly/Singleton-inl.h | 3 +++ folly/Singleton.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/folly/Singleton-inl.h b/folly/Singleton-inl.h index 83dbd2f6..dad943be 100644 --- a/folly/Singleton-inl.h +++ b/folly/Singleton-inl.h @@ -226,6 +226,9 @@ void SingletonHolder::createInstance() { RWSpinLock::ReadHolder rh(&vault_.stateMutex_); if (vault_.state_ == SingletonVault::SingletonVaultState::Quiescing) { + if (vault_.type_ != SingletonVault::Type::Relaxed) { + LOG(FATAL) << "Requesting singleton after vault was destroyed."; + } return; } diff --git a/folly/Singleton.h b/folly/Singleton.h index 297cb8b9..0539e280 100644 --- a/folly/Singleton.h +++ b/folly/Singleton.h @@ -448,6 +448,10 @@ class SingletonVault { return *stackTraceGetterPtr; } + void setType(Type type) { + type_ = type; + } + private: template friend struct detail::SingletonHolder; -- 2.34.1