From 96e52d24ace80e19ce18114680a4a8cdc280158c Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Fri, 5 Dec 2014 14:28:30 -0800 Subject: [PATCH] Revert "Revert "Make folly::Singleton's destruction happen earlier"" 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/folly/experimental/Singleton.h b/folly/experimental/Singleton.h index c42daf01..20416015 100644 --- a/folly/experimental/Singleton.h +++ b/folly/experimental/Singleton.h @@ -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: -- 2.34.1