| 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 // Apart from debug builds, we also enable the thread checker in |  | 
| 12 // builds with DCHECK_ALWAYS_ON so that trybots and waterfall bots |  | 
| 13 // with this define will get the same level of thread checking as |  | 
| 14 // debug bots. |  | 
| 15 #if DCHECK_IS_ON() |  | 
| 16 #define ENABLE_THREAD_CHECKER 1 |  | 
| 17 #else |  | 
| 18 #define ENABLE_THREAD_CHECKER 0 |  | 
| 19 #endif |  | 
| 20 |  | 
| 21 namespace base { | 11 namespace base { | 
| 22 | 12 | 
| 23 // Do nothing implementation, for use in release mode. | 13 // Do nothing implementation, for use in release mode. | 
| 24 // | 14 // | 
| 25 // 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 | 
| 26 // right version for your build configuration. | 16 // right version for your build configuration. | 
| 27 class ThreadCheckerDoNothing { | 17 class ThreadCheckerDoNothing { | 
| 28  public: | 18  public: | 
| 29   bool CalledOnValidThread() const WARN_UNUSED_RESULT { | 19   bool CalledOnValidThread() const WARN_UNUSED_RESULT { | 
| 30     return true; | 20     return true; | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 57 //   void Foo() { | 47 //   void Foo() { | 
| 58 //     DCHECK(thread_checker_.CalledOnValidThread()); | 48 //     DCHECK(thread_checker_.CalledOnValidThread()); | 
| 59 //     ... (do stuff) ... | 49 //     ... (do stuff) ... | 
| 60 //   } | 50 //   } | 
| 61 // | 51 // | 
| 62 //  private: | 52 //  private: | 
| 63 //   ThreadChecker thread_checker_; | 53 //   ThreadChecker thread_checker_; | 
| 64 // } | 54 // } | 
| 65 // | 55 // | 
| 66 // In Release mode, CalledOnValidThread will always return true. | 56 // In Release mode, CalledOnValidThread will always return true. | 
| 67 #if ENABLE_THREAD_CHECKER | 57 #if DCHECK_IS_ON() | 
| 68 class ThreadChecker : public ThreadCheckerImpl { | 58 class ThreadChecker : public ThreadCheckerImpl { | 
| 69 }; | 59 }; | 
| 70 #else | 60 #else | 
| 71 class ThreadChecker : public ThreadCheckerDoNothing { | 61 class ThreadChecker : public ThreadCheckerDoNothing { | 
| 72 }; | 62 }; | 
| 73 #endif  // ENABLE_THREAD_CHECKER | 63 #endif  // DCHECK_IS_ON() | 
| 74 |  | 
| 75 #undef ENABLE_THREAD_CHECKER |  | 
| 76 | 64 | 
| 77 }  // namespace base | 65 }  // namespace base | 
| 78 | 66 | 
| 79 #endif  // BASE_THREADING_THREAD_CHECKER_H_ | 67 #endif  // BASE_THREADING_THREAD_CHECKER_H_ | 
| OLD | NEW | 
|---|