From: Andrii Grynenko Date: Fri, 5 Dec 2014 22:28:30 +0000 (-0800) Subject: Revert "Revert "Make folly::Singleton's destruction happen earlier"" X-Git-Tag: v0.22.0~127 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=96e52d24ace80e19ce18114680a4a8cdc280158c;p=folly.git 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 --- 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: