| OLD | NEW |
| 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 Loading... |
| 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_ |
| OLD | NEW |