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

Side by Side Diff: base/thread_restrictions.h

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
« no previous file with comments | « base/thread_local.h ('k') | base/thread_restrictions.cc » ('j') | 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 #ifndef BASE_THREAD_RESTRICTIONS_H_
6 #define BASE_THREAD_RESTRICTIONS_H_
7
8 namespace base {
9
10 // ThreadRestrictions helps protect threads that should not block from
11 // making blocking calls. It works like this:
12 //
13 // 1) If a thread should not be allowed to make IO calls, mark it:
14 // base::ThreadRestrictions::SetIOAllowed(false);
15 // By default, threads *are* allowed to make IO calls.
16 // In Chrome browser code, IO calls should be proxied to the File thread.
17 //
18 // 2) If a function makes a call that will go out to disk, check whether the
19 // current thread is allowed:
20 // base::ThreadRestrictions::AssertIOAllowed();
21 //
22 // ThreadRestrictions does nothing in release builds; it is debug-only.
23 //
24 class ThreadRestrictions {
25 public:
26 // Set whether the current thread to make IO calls.
27 // Threads start out in the *allowed* state.
28 static void SetIOAllowed(bool allowed);
darin (slow to review) 2010/10/22 06:30:44 I think it is confusing to use the term "IO" here
29
30 // Check whether the current thread is allowed to make IO calls,
31 // and DCHECK if not.
32 static void AssertIOAllowed();
33
34 private:
35 ThreadRestrictions(); // class for namespacing only
darin (slow to review) 2010/10/22 06:30:44 DISALLOW_IMPLICIT_CONSTRUCTORS?
36 };
37
38 // In Release builds, inline the empty definitions of these functions so
39 // that they can be compiled out.
40 #ifdef NDEBUG
41 void ThreadRestrictions::SetIOAllowed(bool allowed) {}
42 void ThreadRestrictions::AssertIOAllowed() {}
43 #endif
44
45 } // namespace base
46
47 #endif // BASE_THREAD_RESTRICTIONS_H_
OLDNEW
« no previous file with comments | « base/thread_local.h ('k') | base/thread_restrictions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698