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

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

Issue 2350663002: Change thread check to race check (Closed)
Patch Set: new impl Created 4 years, 3 months 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
OLDNEW
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // 80 //
81 // In Release mode, CalledOnValidThread will always return true. 81 // In Release mode, CalledOnValidThread will always return true.
82 #if ENABLE_THREAD_CHECKER 82 #if ENABLE_THREAD_CHECKER
83 class LOCKABLE ThreadChecker : public ThreadCheckerImpl { 83 class LOCKABLE ThreadChecker : public ThreadCheckerImpl {
84 }; 84 };
85 #else 85 #else
86 class LOCKABLE ThreadChecker : public ThreadCheckerDoNothing { 86 class LOCKABLE ThreadChecker : public ThreadCheckerDoNothing {
87 }; 87 };
88 #endif // ENABLE_THREAD_CHECKER 88 #endif // ENABLE_THREAD_CHECKER
89 89
90 #undef ENABLE_THREAD_CHECKER 90 // TODO(solenberg): Comment!
91 #if ENABLE_THREAD_CHECKER
92 class LOCKABLE NonReentrantChecker : public CriticalSection {
93 };
94 #else
95 class LOCKABLE NonReentrantChecker {
96 };
97 #endif // ENABLE_THREAD_CHECKER
91 98
92 namespace internal { 99 namespace internal {
93 class SCOPED_LOCKABLE AnnounceOnThread { 100 class SCOPED_LOCKABLE AnnounceOnThread {
94 public: 101 public:
95 template<typename ThreadLikeObject> 102 template<typename ThreadLikeObject>
96 explicit AnnounceOnThread(const ThreadLikeObject* thread_like_object) 103 explicit AnnounceOnThread(const ThreadLikeObject* thread_like_object)
97 EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {} 104 EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {}
98 ~AnnounceOnThread() UNLOCK_FUNCTION() {} 105 ~AnnounceOnThread() UNLOCK_FUNCTION() {}
99 106
100 template<typename ThreadLikeObject> 107 template<typename ThreadLikeObject>
101 static bool IsCurrent(const ThreadLikeObject* thread_like_object) { 108 static bool IsCurrent(const ThreadLikeObject* thread_like_object) {
102 return thread_like_object->IsCurrent(); 109 return thread_like_object->IsCurrent();
103 } 110 }
104 static bool IsCurrent(const rtc::ThreadChecker* checker) { 111 static bool IsCurrent(const rtc::ThreadChecker* checker) {
105 return checker->CalledOnValidThread(); 112 return checker->CalledOnValidThread();
106 } 113 }
107 114
108 private: 115 private:
109 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AnnounceOnThread); 116 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AnnounceOnThread);
110 }; 117 };
111 118
119 class SCOPED_LOCKABLE NonReentrantCheckerScope {
120 public:
121 explicit NonReentrantCheckerScope(const NonReentrantChecker& checker)
122 : try_lock_(&checker) {
123 RTC_DCHECK(try_lock_.locked());
124 }
125 ~NonReentrantCheckerScope() {}
126 private:
127 rtc::TryCritScope try_lock_;
128 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(NonReentrantCheckerScope);
129 };
112 } // namespace internal 130 } // namespace internal
113 } // namespace rtc 131 } // namespace rtc
114 132
115 // RUN_ON/ACCESS_ON/RTC_DCHECK_RUN_ON macros allows to annotate variables are 133 // RUN_ON/ACCESS_ON/RTC_DCHECK_RUN_ON macros allows to annotate variables are
116 // accessed from same thread/task queue. 134 // accessed from same thread/task queue.
117 // Using tools designed to check mutexes, it checks at compile time everywhere 135 // Using tools designed to check mutexes, it checks at compile time everywhere
118 // variable is access, there is a run-time dcheck thread/task queue is correct. 136 // variable is access, there is a run-time dcheck thread/task queue is correct.
119 // 137 //
120 // class ExampleThread { 138 // class ExampleThread {
121 // public: 139 // public:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // same thread/task queue. 195 // same thread/task queue.
178 #define ACCESS_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 196 #define ACCESS_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
179 197
180 // Document if a function expected to be called from same thread/task queue. 198 // Document if a function expected to be called from same thread/task queue.
181 #define RUN_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) 199 #define RUN_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x))
182 200
183 #define RTC_DCHECK_RUN_ON(thread_like_object) \ 201 #define RTC_DCHECK_RUN_ON(thread_like_object) \
184 rtc::internal::AnnounceOnThread thread_announcer(thread_like_object); \ 202 rtc::internal::AnnounceOnThread thread_announcer(thread_like_object); \
185 RTC_DCHECK(rtc::internal::AnnounceOnThread::IsCurrent(thread_like_object)) 203 RTC_DCHECK(rtc::internal::AnnounceOnThread::IsCurrent(thread_like_object))
186 204
205 // TODO(solenberg): COMMENT COMMENT COMMENT.
206 #if ENABLE_THREAD_CHECKER
207 #define __RTC_DCHECK_NON_REENTRANT_NAME(base, line) base ## line
208
209 #define RTC_DCHECK_NON_REENTRANT(checker) \
210 rtc::internal::NonReentrantCheckerScope \
211 __RTC_DCHECK_NON_REENTRANT_NAME(checker, __LINE__)(checker);
kwiberg-webrtc 2016/09/20 10:55:21 The semicolon shouldn't be here.
212 #else
213 #define RTC_DCHECK_NON_REENTRANT(checker)
214 #endif
215
216 #undef ENABLE_THREAD_CHECKER
217
187 #endif // WEBRTC_BASE_THREAD_CHECKER_H_ 218 #endif // WEBRTC_BASE_THREAD_CHECKER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvoiceengine.cc » ('j') | webrtc/media/engine/webrtcvoiceengine.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698