Revert "Revert "Make folly::Singleton's destruction happen earlier""
authorAndrii Grynenko <andrii@fb.com>
Fri, 5 Dec 2014 22:28:30 +0000 (14:28 -0800)
committerDave Watson <davejwatson@fb.com>
Thu, 11 Dec 2014 16:01:01 +0000 (08:01 -0800)
Summary:
This reverts commit 7871df125fc1fbe5d8030a41e21b8241b25d4e62.

As explained in t5763478, I don't see good reason for a revert.
Also the errors under question shouldn't show up after D1720841.

Test Plan: revert-hammer

Reviewed By: stepan@fb.com

Subscribers: njormrod, folly-diffs@

FB internal diff: D1722928

Tasks: 5763478

Signature: t1:1722928:1417818663:1fe402d14c0cf389fb3611355db270c5f2c33738

folly/experimental/Singleton.h

index c42daf01f075d7fa2d9ebac1f30e5ac4510833bf..20416015883eceffdade7e6f4d76444f61419b98 100644 (file)
@@ -208,7 +208,7 @@ class SingletonVault {
   // Mark registration is complete; no more singletons can be
   // registered at this point.
   void registrationComplete() {
-    scheduleDestroyInstances();
+    std::atexit([](){ SingletonVault::singleton()->destroyInstances(); });
 
     RWSpinLock::WriteHolder wh(&stateMutex_);
 
@@ -329,6 +329,9 @@ class SingletonVault {
     SingletonEntry(SingletonEntry&&) = delete;
   };
 
+  // This method only matters if registrationComplete() is never called.
+  // Otherwise destroyInstances is scheduled to be executed atexit.
+  //
   // Initializes static object, which calls destroyInstances on destruction.
   // Used to have better deletion ordering with singleton not managed by
   // folly::Singleton. The desruction will happen in the following order: