OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return checker->CalledOnValidThread(); | 96 return checker->CalledOnValidThread(); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AnnounceOnThread); | 100 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AnnounceOnThread); |
101 }; | 101 }; |
102 | 102 |
103 } // namespace internal | 103 } // namespace internal |
104 } // namespace rtc | 104 } // namespace rtc |
105 | 105 |
106 // RUN_ON/ACCESS_ON/RTC_DCHECK_RUN_ON macros allows to annotate variables are | 106 // RTC_RUN_ON/RTC_ACCESS_ON/RTC_DCHECK_RUN_ON macros allows to annotate |
107 // accessed from same thread/task queue. | 107 // variables are accessed from same thread/task queue. |
108 // Using tools designed to check mutexes, it checks at compile time everywhere | 108 // Using tools designed to check mutexes, it checks at compile time everywhere |
109 // variable is access, there is a run-time dcheck thread/task queue is correct. | 109 // variable is access, there is a run-time dcheck thread/task queue is correct. |
110 // | 110 // |
111 // class ExampleThread { | 111 // class ExampleThread { |
112 // public: | 112 // public: |
113 // void NeedVar1() { | 113 // void NeedVar1() { |
114 // RTC_DCHECK_RUN_ON(network_thread_); | 114 // RTC_DCHECK_RUN_ON(network_thread_); |
115 // transport_->Send(); | 115 // transport_->Send(); |
116 // } | 116 // } |
117 // | 117 // |
118 // private: | 118 // private: |
119 // rtc::Thread* network_thread_; | 119 // rtc::Thread* network_thread_; |
120 // int transport_ ACCESS_ON(network_thread_); | 120 // int transport_ RTC_ACCESS_ON(network_thread_); |
121 // }; | 121 // }; |
122 // | 122 // |
123 // class ExampleThreadChecker { | 123 // class ExampleThreadChecker { |
124 // public: | 124 // public: |
125 // int CalledFromPacer() RUN_ON(pacer_thread_checker_) { | 125 // int CalledFromPacer() RTC_RUN_ON(pacer_thread_checker_) { |
126 // return var2_; | 126 // return var2_; |
127 // } | 127 // } |
128 // | 128 // |
129 // void CallMeFromPacer() { | 129 // void CallMeFromPacer() { |
130 // RTC_DCHECK_RUN_ON(&pacer_thread_checker_) | 130 // RTC_DCHECK_RUN_ON(&pacer_thread_checker_) |
131 // << "Should be called from pacer"; | 131 // << "Should be called from pacer"; |
132 // CalledFromPacer(); | 132 // CalledFromPacer(); |
133 // } | 133 // } |
134 // | 134 // |
135 // private: | 135 // private: |
136 // int pacer_var_ ACCESS_ON(pacer_thread_checker_); | 136 // int pacer_var_ RTC_ACCESS_ON(pacer_thread_checker_); |
137 // rtc::ThreadChecker pacer_thread_checker_; | 137 // rtc::ThreadChecker pacer_thread_checker_; |
138 // }; | 138 // }; |
139 // | 139 // |
140 // class TaskQueueExample { | 140 // class TaskQueueExample { |
141 // public: | 141 // public: |
142 // class Encoder { | 142 // class Encoder { |
143 // public: | 143 // public: |
144 // rtc::TaskQueue* Queue() { return encoder_queue_; } | 144 // rtc::TaskQueue* Queue() { return encoder_queue_; } |
145 // void Encode() { | 145 // void Encode() { |
146 // RTC_DCHECK_RUN_ON(encoder_queue_); | 146 // RTC_DCHECK_RUN_ON(encoder_queue_); |
147 // DoSomething(var_); | 147 // DoSomething(var_); |
148 // } | 148 // } |
149 // | 149 // |
150 // private: | 150 // private: |
151 // rtc::TaskQueue* const encoder_queue_; | 151 // rtc::TaskQueue* const encoder_queue_; |
152 // Frame var_ ACCESS_ON(encoder_queue_); | 152 // Frame var_ RTC_ACCESS_ON(encoder_queue_); |
153 // }; | 153 // }; |
154 // | 154 // |
155 // void Encode() { | 155 // void Encode() { |
156 // // Will fail at runtime when DCHECK is enabled: | 156 // // Will fail at runtime when DCHECK is enabled: |
157 // // encoder_->Encode(); | 157 // // encoder_->Encode(); |
158 // // Will work: | 158 // // Will work: |
159 // rtc::scoped_ref_ptr<Encoder> encoder = encoder_; | 159 // rtc::scoped_ref_ptr<Encoder> encoder = encoder_; |
160 // encoder_->Queue()->PostTask([encoder] { encoder->Encode(); }); | 160 // encoder_->Queue()->PostTask([encoder] { encoder->Encode(); }); |
161 // } | 161 // } |
162 // | 162 // |
163 // private: | 163 // private: |
164 // rtc::scoped_ref_ptr<Encoder> encoder_; | 164 // rtc::scoped_ref_ptr<Encoder> encoder_; |
165 // } | 165 // } |
166 | 166 |
167 // Document if a variable/field is not shared and should be accessed from | 167 // Document if a variable/field is not shared and should be accessed from |
168 // same thread/task queue. | 168 // same thread/task queue. |
169 #define ACCESS_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) | 169 #define ACCESS_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) |
| 170 #define RTC_ACCESS_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) |
170 | 171 |
171 // Document if a function expected to be called from same thread/task queue. | 172 // Document if a function expected to be called from same thread/task queue. |
172 #define RUN_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) | 173 #define RUN_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) |
| 174 #define RTC_RUN_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required
(x)) |
173 | 175 |
174 #define RTC_DCHECK_RUN_ON(thread_like_object) \ | 176 #define RTC_DCHECK_RUN_ON(thread_like_object) \ |
175 rtc::internal::AnnounceOnThread thread_announcer(thread_like_object); \ | 177 rtc::internal::AnnounceOnThread thread_announcer(thread_like_object); \ |
176 RTC_DCHECK(rtc::internal::AnnounceOnThread::IsCurrent(thread_like_object)) | 178 RTC_DCHECK(rtc::internal::AnnounceOnThread::IsCurrent(thread_like_object)) |
177 | 179 |
178 #endif // WEBRTC_RTC_BASE_THREAD_CHECKER_H_ | 180 #endif // WEBRTC_RTC_BASE_THREAD_CHECKER_H_ |
OLD | NEW |