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

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

Issue 2542403003: Make ThreadChecker zero-sized
Patch Set: Created 4 years 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 | « no previous file | base/threading/thread_checker_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_THREAD_CHECKER_H_ 5 #ifndef BASE_THREADING_THREAD_CHECKER_H_
6 #define BASE_THREADING_THREAD_CHECKER_H_ 6 #define BASE_THREADING_THREAD_CHECKER_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_checker_impl.h" 9 #include "base/threading/thread_checker_impl.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 // Do nothing implementation, for use in release mode. 13 // Do nothing implementation, for use in release mode.
14 // 14 //
15 // Note: You should almost always use the ThreadChecker class to get the 15 // Note: You should almost always use the ThreadChecker class to get the
16 // right version for your build configuration. 16 // right version for your build configuration.
17 class ThreadCheckerDoNothing { 17 class ThreadCheckerDoNothing {
18 public: 18 public:
19 bool CalledOnValidThread() const WARN_UNUSED_RESULT { 19 bool CalledOnValidThread() const WARN_UNUSED_RESULT {
20 return true; 20 return true;
21 } 21 }
22 22
23 void DetachFromThread() {} 23 void DetachFromThread() {}
24
25 // Trick the compiler into making ThreadCheckerDoNothing zero-length.
26 int make_thread_checker_zero_sized_[0];
24 }; 27 };
25 28
26 // ThreadChecker is a helper class used to help verify that some methods of a 29 // ThreadChecker is a helper class used to help verify that some methods of a
27 // class are called from the same thread. It provides identical functionality to 30 // class are called from the same thread. It provides identical functionality to
28 // base::NonThreadSafe, but it is meant to be held as a member variable, rather 31 // base::NonThreadSafe, but it is meant to be held as a member variable, rather
29 // than inherited from base::NonThreadSafe. 32 // than inherited from base::NonThreadSafe.
30 // 33 //
31 // While inheriting from base::NonThreadSafe may give a clear indication about 34 // While inheriting from base::NonThreadSafe may give a clear indication about
32 // the thread-safety of a class, it may also lead to violations of the style 35 // the thread-safety of a class, it may also lead to violations of the style
33 // guide with regard to multiple inheritance. The choice between having a 36 // guide with regard to multiple inheritance. The choice between having a
(...skipping 30 matching lines...) Expand all
64 class ThreadChecker : public ThreadCheckerImpl { 67 class ThreadChecker : public ThreadCheckerImpl {
65 }; 68 };
66 #else 69 #else
67 class ThreadChecker : public ThreadCheckerDoNothing { 70 class ThreadChecker : public ThreadCheckerDoNothing {
68 }; 71 };
69 #endif // DCHECK_IS_ON() 72 #endif // DCHECK_IS_ON()
70 73
71 } // namespace base 74 } // namespace base
72 75
73 #endif // BASE_THREADING_THREAD_CHECKER_H_ 76 #endif // BASE_THREADING_THREAD_CHECKER_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/thread_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698