Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: base/thread_restrictions.cc

Issue 3956003: ThreadRestrictions: leak the thread local variable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better impl Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/thread_restrictions.h" 5 #include "base/thread_restrictions.h"
6 6
7 // This entire file is compiled out in Release mode. 7 // This entire file is compiled out in Release mode.
8 #ifndef NDEBUG 8 #ifndef NDEBUG
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/thread_local.h" 12 #include "base/thread_local.h"
13 13
14 namespace { 14 namespace {
15 15
16 static base::LazyInstance<base::ThreadLocalBoolean> 16 base::LazyInstance<base::ThreadLocalBoolean,
willchan no longer on Chromium 2010/10/21 20:26:50 Why don't you just move this anonymous namespace w
17 base::LeakyLazyInstanceTraits<base::ThreadLocalBoolean> >
17 g_io_disallowed(base::LINKER_INITIALIZED); 18 g_io_disallowed(base::LINKER_INITIALIZED);
18 19
19 } // anonymous namespace 20 } // anonymous namespace
20 21
21 namespace base { 22 namespace base {
22 23
23 // static 24 // static
24 void ThreadRestrictions::SetIOAllowed(bool allowed) { 25 void ThreadRestrictions::SetIOAllowed(bool allowed) {
25 g_io_disallowed.Get().Set(!allowed); 26 g_io_disallowed.Get().Set(!allowed);
26 } 27 }
27 28
28 // static 29 // static
29 void ThreadRestrictions::AssertIOAllowed() { 30 void ThreadRestrictions::AssertIOAllowed() {
30 if (g_io_disallowed.Get().Get()) { 31 if (g_io_disallowed.Get().Get()) {
31 LOG(FATAL) << 32 LOG(FATAL) <<
32 "Function marked as IO-only was called from a thread that " 33 "Function marked as IO-only was called from a thread that "
33 "disallows IO! If this thread really should be allowed to " 34 "disallows IO! If this thread really should be allowed to "
34 "make IO calls, adjust the call to " 35 "make IO calls, adjust the call to "
35 "base::ThreadRestrictions::SetIOAllowed() in this thread's " 36 "base::ThreadRestrictions::SetIOAllowed() in this thread's "
36 "startup."; 37 "startup.";
37 } 38 }
38 } 39 }
39 40
40 } // namespace base 41 } // namespace base
41 42
42 #endif // NDEBUG 43 #endif // NDEBUG
OLDNEW
« base/lazy_instance_unittest.cc ('K') | « base/lazy_instance_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698