From: Andrii Grynenko Date: Fri, 19 Aug 2016 18:55:15 +0000 (-0700) Subject: Don't allow getting singleton after shutdown in strict mode X-Git-Tag: v2016.08.22.00~11 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c7656e1f39228fe5f78658c1f49c980a8ac597e4;p=folly.git 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 --- 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;