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

Side by Side Diff: base/threading/thread_restrictions.h

Issue 6729002: Base: A few more files using BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 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
« no previous file with comments | « base/threading/thread_local_storage.h ('k') | base/time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_ 5 #ifndef BASE_THREADING_THREAD_RESTRICTIONS_H_
6 #define BASE_THREADING_THREAD_RESTRICTIONS_H_ 6 #define BASE_THREADING_THREAD_RESTRICTIONS_H_
7 7
8 #include "base/base_api.h"
8 #include "base/basictypes.h" 9 #include "base/basictypes.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 // Certain behavior is disallowed on certain threads. ThreadRestrictions helps 13 // Certain behavior is disallowed on certain threads. ThreadRestrictions helps
13 // enforce these rules. Examples of such rules: 14 // enforce these rules. Examples of such rules:
14 // 15 //
15 // * Do not do blocking IO (makes the thread janky) 16 // * Do not do blocking IO (makes the thread janky)
16 // * Do not access Singleton/LazyInstance (may lead to shutdown crashes) 17 // * Do not access Singleton/LazyInstance (may lead to shutdown crashes)
17 // 18 //
(...skipping 10 matching lines...) Expand all
28 // 29 //
29 // ThreadRestrictions does nothing in release builds; it is debug-only. 30 // ThreadRestrictions does nothing in release builds; it is debug-only.
30 // 31 //
31 // Style tip: where should you put AssertIOAllowed checks? It's best 32 // Style tip: where should you put AssertIOAllowed checks? It's best
32 // if you put them as close to the disk access as possible, at the 33 // if you put them as close to the disk access as possible, at the
33 // lowest level. This rule is simple to follow and helps catch all 34 // lowest level. This rule is simple to follow and helps catch all
34 // callers. For example, if your function GoDoSomeBlockingDiskCall() 35 // callers. For example, if your function GoDoSomeBlockingDiskCall()
35 // only calls other functions in Chrome and not fopen(), you should go 36 // only calls other functions in Chrome and not fopen(), you should go
36 // add the AssertIOAllowed checks in the helper functions. 37 // add the AssertIOAllowed checks in the helper functions.
37 38
38 class ThreadRestrictions { 39 class BASE_API ThreadRestrictions {
39 public: 40 public:
40 // Constructing a ScopedAllowIO temporarily allows IO for the current 41 // Constructing a ScopedAllowIO temporarily allows IO for the current
41 // thread. Doing this is almost certainly always incorrect. 42 // thread. Doing this is almost certainly always incorrect.
42 class ScopedAllowIO { 43 class BASE_API ScopedAllowIO {
43 public: 44 public:
44 ScopedAllowIO() { previous_value_ = SetIOAllowed(true); } 45 ScopedAllowIO() { previous_value_ = SetIOAllowed(true); }
45 ~ScopedAllowIO() { SetIOAllowed(previous_value_); } 46 ~ScopedAllowIO() { SetIOAllowed(previous_value_); }
46 private: 47 private:
47 // Whether IO is allowed when the ScopedAllowIO was constructed. 48 // Whether IO is allowed when the ScopedAllowIO was constructed.
48 bool previous_value_; 49 bool previous_value_;
49 50
50 DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO); 51 DISALLOW_COPY_AND_ASSIGN(ScopedAllowIO);
51 }; 52 };
52 53
53 // Constructing a ScopedAllowSingleton temporarily allows accessing for the 54 // Constructing a ScopedAllowSingleton temporarily allows accessing for the
54 // current thread. Doing this is almost always incorrect. 55 // current thread. Doing this is almost always incorrect.
55 class ScopedAllowSingleton { 56 class BASE_API ScopedAllowSingleton {
56 public: 57 public:
57 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); } 58 ScopedAllowSingleton() { previous_value_ = SetSingletonAllowed(true); }
58 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); } 59 ~ScopedAllowSingleton() { SetSingletonAllowed(previous_value_); }
59 private: 60 private:
60 // Whether singleton use is allowed when the ScopedAllowSingleton was 61 // Whether singleton use is allowed when the ScopedAllowSingleton was
61 // constructed. 62 // constructed.
62 bool previous_value_; 63 bool previous_value_;
63 64
64 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton); 65 DISALLOW_COPY_AND_ASSIGN(ScopedAllowSingleton);
65 }; 66 };
(...skipping 25 matching lines...) Expand all
91 static void AssertSingletonAllowed() {} 92 static void AssertSingletonAllowed() {}
92 #endif 93 #endif
93 94
94 private: 95 private:
95 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions); 96 DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadRestrictions);
96 }; 97 };
97 98
98 } // namespace base 99 } // namespace base
99 100
100 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_ 101 #endif // BASE_THREADING_THREAD_RESTRICTIONS_H_
OLDNEW
« no previous file with comments | « base/threading/thread_local_storage.h ('k') | base/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698