diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-13 23:44:20 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-13 23:44:20 +0000 |
commit | 2902738f2a36d4f0ef22e25369e653f4eda2a7aa (patch) | |
tree | 582ce3d66406a222edb686625227c1eea475d285 /base/thread_restrictions.h | |
parent | 2d39894da98b2ae12b4052776c4fcf23d1bf2442 (diff) | |
download | chromium_src-2902738f2a36d4f0ef22e25369e653f4eda2a7aa.zip chromium_src-2902738f2a36d4f0ef22e25369e653f4eda2a7aa.tar.gz chromium_src-2902738f2a36d4f0ef22e25369e653f4eda2a7aa.tar.bz2 |
Revert 65996 (test breakage) - Disallow Singleton and LazyInstance on non-joinable threads.
Fix all known instances or explicitly allow them. Usually the fix involves switching from Default traits to Lazy traits.
BUG=61753
TEST=none
Review URL: http://codereview.chromium.org/4635012
TBR=willchan@chromium.org
Review URL: http://codereview.chromium.org/4980001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_restrictions.h')
-rw-r--r-- | base/thread_restrictions.h | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/base/thread_restrictions.h b/base/thread_restrictions.h index 2d73927..a10aaec 100644 --- a/base/thread_restrictions.h +++ b/base/thread_restrictions.h @@ -9,13 +9,8 @@ namespace base { -// Certain behavior is disallowed on certain threads. ThreadRestrictions helps -// enforce these rules. Examples of such rules: -// -// * Do not do blocking IO (makes the thread janky) -// * Do not access Singleton/LazyInstance (may lead to shutdown crashes) -// -// Here's more about how the IO protection works: +// ThreadRestrictions helps protect threads that should not block from +// making blocking calls. It works like this: // // 1) If a thread should not be allowed to make IO calls, mark it: // base::ThreadRestrictions::SetIOAllowed(false); @@ -50,20 +45,6 @@ class ThreadRestrictions { DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO); }; - // Constructing a ScopedAllowSingleton temporarily allows accessing for the - // current thread. Doing this is almost always incorrect. - class ScopedAllowSingleton { - public: - ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } - ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } - private: - // Whether singleton use is allowed when the ScopedAllowSingleton was - // constructed. - bool previous_value_; - - DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); - }; - #ifndef NDEBUG // Set whether the current thread to make IO calls. // Threads start out in the *allowed* state. @@ -74,25 +55,15 @@ class ThreadRestrictions { // and DCHECK if not. See the block comment above the class for // a discussion of where to add these checks. static void AssertIOAllowed(); - - // Set whether the current thread can use singletons. Returns the previous - // value. - static bool SetSingletonAllowed(bool allowed); - - // Check whether the current thread is allowed to use singletons (Singleton / - // LazyInstance). DCHECKs if not. - static void AssertSingletonAllowed(); #else // In Release builds, inline the empty definitions of these functions so // that they can be compiled out. static bool SetIOAllowed(bool allowed) { return true; } static void AssertIOAllowed() {} - static bool SetSingletonAllowed(bool allowed) { return true; } - static void AssertSingletonAllowed() {} #endif private: - DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); + ThreadRestrictions(); // class for namespacing only }; } // namespace base |