Don't allow getting singleton after shutdown in strict mode
authorAndrii Grynenko <andrii@fb.com>
Fri, 19 Aug 2016 18:55:15 +0000 (11:55 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Fri, 19 Aug 2016 19:08:42 +0000 (12:08 -0700)
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
folly/Singleton.h

index 83dbd2f6eb07bec7ae88271f28363a6e8b1bcddb..dad943be7184b09011326bf20cbc6fdade669873 100644 (file)
@@ -226,6 +226,9 @@ void SingletonHolder<T>::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;
   }
 
index 297cb8b938b4070ef129d449feaf9712c5e5b559..0539e28055e294a05bbd18d167a69cbe071e5dc3 100644 (file)
@@ -448,6 +448,10 @@ class SingletonVault {
     return *stackTraceGetterPtr;
   }
 
+  void setType(Type type) {
+    type_ = type;
+  }
+
  private:
   template <typename T>
   friend struct detail::SingletonHolder;