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

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: Fix ODR violation Created 8 years, 5 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 | base/threading/non_thread_safe_unittest.cc » ('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) 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 // See comment at top of thread_checker.h
16 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
17 #define ENABLE_NON_THREAD_SAFE 1
18 #else
19 #define ENABLE_NON_THREAD_SAFE 0
20 #endif
21
22 #if ENABLE_NON_THREAD_SAFE
16 #include "base/threading/non_thread_safe_impl.h" 23 #include "base/threading/non_thread_safe_impl.h"
17 #endif 24 #endif
18 25
19 namespace base { 26 namespace base {
20 27
21 // Do nothing implementation of NonThreadSafe, for release mode. 28 // Do nothing implementation of NonThreadSafe, for release mode.
22 // 29 //
23 // Note: You should almost always use the NonThreadSafe class to get 30 // Note: You should almost always use the NonThreadSafe class to get
24 // the right version of the class for your build configuration. 31 // the right version of the class for your build configuration.
25 class NonThreadSafeDoNothing { 32 class NonThreadSafeDoNothing {
(...skipping 21 matching lines...) Expand all
47 // DCHECK(CalledOnValidThread()); 54 // DCHECK(CalledOnValidThread());
48 // ... (do stuff) ... 55 // ... (do stuff) ...
49 // } 56 // }
50 // } 57 // }
51 // 58 //
52 // Note that base::ThreadChecker offers identical functionality to 59 // Note that base::ThreadChecker offers identical functionality to
53 // NonThreadSafe, but does not require inheritence. In general, it is preferable 60 // NonThreadSafe, but does not require inheritence. In general, it is preferable
54 // to have a base::ThreadChecker as a member, rather than inherit from 61 // to have a base::ThreadChecker as a member, rather than inherit from
55 // NonThreadSafe. For more details about when to choose one over the other, see 62 // NonThreadSafe. For more details about when to choose one over the other, see
56 // the documentation for base::ThreadChecker. 63 // the documentation for base::ThreadChecker.
57 // 64 #if ENABLE_NON_THREAD_SAFE
58 // In Release mode, CalledOnValidThread will always return true. 65 class NonThreadSafe : public NonThreadSafeImpl {
59 #ifndef NDEBUG 66 };
60 typedef NonThreadSafeImpl NonThreadSafe;
61 #else 67 #else
62 typedef NonThreadSafeDoNothing NonThreadSafe; 68 class NonThreadSafe : public NonThreadSafeDoNothing {
63 #endif // NDEBUG 69 };
70 #endif // ENABLE_NON_THREAD_SAFE
71
72 #undef ENABLE_NON_THREAD_SAFE
64 73
65 } // namespace base 74 } // namespace base
66 75
67 #endif // BASE_NON_THREAD_SAFE_H_ 76 #endif // BASE_NON_THREAD_SAFE_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/non_thread_safe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698