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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 // public: | 56 // public: |
57 // void Foo() { | 57 // void Foo() { |
58 // DCHECK(thread_checker_.CalledOnValidThread()); | 58 // DCHECK(thread_checker_.CalledOnValidThread()); |
59 // ... (do stuff) ... | 59 // ... (do stuff) ... |
60 // } | 60 // } |
61 // | 61 // |
62 // private: | 62 // private: |
63 // ThreadChecker thread_checker_; | 63 // ThreadChecker thread_checker_; |
64 // } | 64 // } |
65 // | 65 // |
66 // Note that, when enabled, CalledOnValidThread() returns false when called from | |
67 // tasks posted to SingleThreadTaskRunners bound to different sequences, even if | |
68 // the tasks happen to run on the same thread (e.g. two independent TaskRunners | |
69 // with ExecutionMode::SINGLE_THREADED on the TaskScheduler that happen to share | |
70 // a thread). Also, CalledOnValidThread() returns false when called from a non- | |
71 // single-threaded task which is associated with a SequenceToken (e.g. a task | |
72 // posted with ExecutionMode::PARALLEL or ExecutionMode::SEQUENCED to the | |
gab
2016/07/21 21:14:24
PARALLEL won't have a SequenceToken -- keeping the
fdoray
2016/07/25 13:24:28
keeping the example about SEQUENCED to avoid confu
gab
2016/07/25 14:09:31
Ah right, but IMO that's an implementation detail
| |
73 // TaskScheduler). | |
74 // | |
66 // In Release mode, CalledOnValidThread will always return true. | 75 // In Release mode, CalledOnValidThread will always return true. |
67 #if ENABLE_THREAD_CHECKER | 76 #if ENABLE_THREAD_CHECKER |
68 class ThreadChecker : public ThreadCheckerImpl { | 77 class ThreadChecker : public ThreadCheckerImpl { |
69 }; | 78 }; |
70 #else | 79 #else |
71 class ThreadChecker : public ThreadCheckerDoNothing { | 80 class ThreadChecker : public ThreadCheckerDoNothing { |
72 }; | 81 }; |
73 #endif // ENABLE_THREAD_CHECKER | 82 #endif // ENABLE_THREAD_CHECKER |
74 | 83 |
75 #undef ENABLE_THREAD_CHECKER | 84 #undef ENABLE_THREAD_CHECKER |
76 | 85 |
77 } // namespace base | 86 } // namespace base |
78 | 87 |
79 #endif // BASE_THREADING_THREAD_CHECKER_H_ | 88 #endif // BASE_THREADING_THREAD_CHECKER_H_ |
OLD | NEW |