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

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

Issue 10636044: Enable base::NonThreadSafe when DCHECK_ALWAYS_ON is set (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add back IWYU violation, address separately Created 8 years, 6 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 | « no previous file | 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_NON_THREAD_SAFE_H_ 5 #ifndef BASE_THREADING_NON_THREAD_SAFE_H_
6 #define BASE_THREADING_NON_THREAD_SAFE_H_ 6 #define BASE_THREADING_NON_THREAD_SAFE_H_
7 #pragma once 7 #pragma once
8 8
9 // Classes deriving from NonThreadSafe may need to supress MSVC warning 4275: 9 // Classes deriving from NonThreadSafe may need to suppress MSVC warning 4275:
10 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'. 10 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
11 // There is a specific macro to do it: NON_EXPORTED_BASE(), defined in 11 // There is a specific macro to do it: NON_EXPORTED_BASE(), defined in
12 // compiler_specific.h 12 // compiler_specific.h
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 14
15 #ifndef NDEBUG 15 // Apart from debug builds, we also enable the NonThreadSafe checks in
16 // builds with DCHECK_ALWAYS_ON so that trybots and waterfall bots
17 // with this define will get the same level of thread checking as
18 // debug bots.
19 //
20 // Note that this does not perfectly match situations where DCHECK is
21 // enabled. For example a non-official release build may have
22 // DCHECK_ALWAYS_ON undefined (and therefore NonThreadSafe would be
23 // disabled) but have DCHECKs enabled at runtime.
jam 2012/06/26 01:56:30 nit: instead of copying the comment, I would just
24 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
25 #define ENABLE_NON_THREAD_SAFE 1
26 #else
27 #define ENABLE_NON_THREAD_SAFE 0
28 #endif
29
30 #if ENABLE_NON_THREAD_SAFE
16 #include "base/threading/non_thread_safe_impl.h" 31 #include "base/threading/non_thread_safe_impl.h"
17 #endif 32 #endif
18 33
19 namespace base { 34 namespace base {
20 35
21 // Do nothing implementation of NonThreadSafe, for release mode. 36 // Do nothing implementation of NonThreadSafe, for release mode.
22 // 37 //
23 // Note: You should almost always use the NonThreadSafe class to get 38 // Note: You should almost always use the NonThreadSafe class to get
24 // the right version of the class for your build configuration. 39 // the right version of the class for your build configuration.
25 class NonThreadSafeDoNothing { 40 class NonThreadSafeDoNothing {
(...skipping 20 matching lines...) Expand all
46 // DCHECK(CalledOnValidThread()); 61 // DCHECK(CalledOnValidThread());
47 // ... (do stuff) ... 62 // ... (do stuff) ...
48 // } 63 // }
49 // } 64 // }
50 // 65 //
51 // Note that base::ThreadChecker offers identical functionality to 66 // Note that base::ThreadChecker offers identical functionality to
52 // NonThreadSafe, but does not require inheritence. In general, it is preferable 67 // NonThreadSafe, but does not require inheritence. In general, it is preferable
53 // to have a base::ThreadChecker as a member, rather than inherit from 68 // to have a base::ThreadChecker as a member, rather than inherit from
54 // NonThreadSafe. For more details about when to choose one over the other, see 69 // NonThreadSafe. For more details about when to choose one over the other, see
55 // the documentation for base::ThreadChecker. 70 // the documentation for base::ThreadChecker.
56 // 71 #if ENABLE_NON_THREAD_SAFE
57 // In Release mode, CalledOnValidThread will always return true.
58 #ifndef NDEBUG
59 class NonThreadSafe : public NonThreadSafeImpl { 72 class NonThreadSafe : public NonThreadSafeImpl {
60 }; 73 };
61 #else 74 #else
62 class NonThreadSafe : public NonThreadSafeDoNothing { 75 class NonThreadSafe : public NonThreadSafeDoNothing {
63 }; 76 };
64 #endif // NDEBUG 77 #endif // ENABLE_NON_THREAD_SAFE
78
79 #undef ENABLE_NON_THREAD_SAFE
65 80
66 } // namespace base 81 } // namespace base
67 82
68 #endif // BASE_NON_THREAD_SAFE_H_ 83 #endif // BASE_NON_THREAD_SAFE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698