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

Unified Diff: webrtc/base/thread_scope.h

Issue 1967193002: ThreadScope concept to check variable accessed on correct thread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: generalized ThreadScope Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/thread_checker.h ('k') | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/thread_scope.h
diff --git a/webrtc/base/thread_scope.h b/webrtc/base/thread_scope.h
new file mode 100644
index 0000000000000000000000000000000000000000..599922572b129b3b525fc7dd6e3b72bdc613a2f1
--- /dev/null
+++ b/webrtc/base/thread_scope.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_BASE_THREAD_SCOPE_H_
+#define WEBRTC_BASE_THREAD_SCOPE_H_
+
+#include "webrtc/base/checks.h"
+// #include webrtc/base/task_queue.h"
+#include "webrtc/base/thread.h"
+#include "webrtc/base/thread_annotations.h"
+#include "webrtc/base/thread_checker.h"
+
+namespace rtc {
+// ThreadScope mimic CritScope.
+class SCOPED_LOCKABLE ThreadScope {
+ public:
+ template<typename ThreadLikeObject>
+ explicit ThreadScope(const ThreadLikeObject* thread)
+ EXCLUSIVE_LOCK_FUNCTION(thread) {}
+
+ static bool IsCurrent(const Thread* thread) {
+ return thread->IsCurrent();
+ }
+ static bool IsCurrent(const ThreadChecker* checker) {
+ return checker->CalledOnValidThread();
+ }
+ /*
+ static bool IsCurrent(const TaskQueue* queue) {
+ return queue->IsCurrent();
+ } */
+
+ ~ThreadScope() UNLOCK_FUNCTION() {}
+ private:
+ RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ThreadScope);
+};
+
+} // namespace rtc
+
+// Macro so that DCHECK report correct __FILE__ and __LINE__
+#define RTC_DCHECK_RUN_ON(thread_like_object) \
+ rtc::ThreadScope check(thread_like_object); \
+ RTC_DCHECK(rtc::ThreadScope::IsCurrent(thread_like_object))
+
+// Forward macros to avoid word 'lock' when annotating threads
+#define RTC_MUST_RUN_ON(thread_like_object) \
+ EXCLUSIVE_LOCKS_REQUIRED(thread_like_object)
+#define RTC_MUST_BE_ACCESSED_FROM(thread_like_object) \
+ GUARDED_BY(thread_like_object)
+
+#endif // WEBRTC_BASE_THREAD_SCOPE_H_
« no previous file with comments | « webrtc/base/thread_checker.h ('k') | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698