From 7c9f763d8b5867b227ab245ebd584f4a5eb6d3f0 Mon Sep 17 00:00:00 2001 From: "timurrrr@chromium.org" Date: Tue, 9 Nov 2010 14:27:51 +0000 Subject: Make Singleton::OnExit explicity not-threadsafe This should help track down Singleton mis-usage, e.g. BUG=61753 TEST=trybots Review URL: http://codereview.chromium.org/4430003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65527 0039d316-1c4b-4281-b951-d872f2087c98 --- base/singleton.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'base') diff --git a/base/singleton.h b/base/singleton.h index 3fe16ce..564b686 100644 --- a/base/singleton.h +++ b/base/singleton.h @@ -239,12 +239,14 @@ class Singleton { private: // Adapter function for use with AtExit(). This should be called single - // threaded, but we might as well take the precautions anyway. + // threaded, so don't use atomic operations. + // Calling OnExit while singleton is in use by other threads is a mistake. static void OnExit(void* unused) { // AtExit should only ever be register after the singleton instance was // created. We should only ever get here with a valid instance_ pointer. - Traits::Delete(reinterpret_cast( - base::subtle::NoBarrier_AtomicExchange(&instance_, 0))); + Traits::Delete( + reinterpret_cast(base::subtle::NoBarrier_Load(&instance_))); + instance_ = 0; } static base::subtle::AtomicWord instance_; }; -- cgit v1.1