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

Side by Side Diff: base/thread_restrictions.cc

Issue 3824006: base: add a thread-safety assertion checker (Closed)
Patch Set: fix function name 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
« base/thread_restrictions.h ('K') | « base/thread_restrictions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/thread_restrictions.h"
6
7 // This entire file is compiled out in Release mode.
8 #ifndef NDEBUG
9
10 #include "base/lazy_instance.h"
11 #include "base/logging.h"
12 #include "base/thread_local.h"
13
14 namespace {
15
16 static base::LazyInstance<base::ThreadLocalBoolean>
17 g_io_disallowed(base::LINKER_INITIALIZED);
18
19 } // anonymous namespace
20
21 namespace base {
22
23 // static
24 void ThreadRestrictions::SetIOAllowed(bool allowed) {
25 g_io_disallowed.Get().Set(!allowed);
26 }
27
28 // static
29 void ThreadRestrictions::AssertIOAllowed() {
30 if (g_io_disallowed.Get().Get()) {
31 LOG(FATAL) <<
32 "Function marked as IO-only was called from a thread that "
33 "disallows IO! If this thread really should be allowed to "
34 "make IO calls, adjust the call to "
35 "base::ThreadRestrictions::SetIOAllowed() in this thread's "
36 "startup.";
37 }
38 }
39
40 } // namespace base
41
42 #endif // NDEBUG
OLDNEW
« base/thread_restrictions.h ('K') | « base/thread_restrictions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698