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

Unified Diff: webrtc/base/thread_checker_unittest.cc

Issue 1981893002: Adds macros to annotate variables and functions used from same thread or queue. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix example 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') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/thread_checker_unittest.cc
diff --git a/webrtc/base/thread_checker_unittest.cc b/webrtc/base/thread_checker_unittest.cc
index 372f6f4a77fb921d1801fd0fb8e171346b727dc1..0a855a1a94032097a0e99eba22df9a8d6c50b4e0 100644
--- a/webrtc/base/thread_checker_unittest.cc
+++ b/webrtc/base/thread_checker_unittest.cc
@@ -15,6 +15,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/task_queue.h"
#include "webrtc/base/thread.h"
#include "webrtc/base/thread_checker.h"
@@ -194,6 +195,61 @@ TEST(ThreadCheckerTest, DetachFromThreadInRelease) {
#endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER
+class ThreadAnnotateTest {
+ public:
+ // Next two function should create warnings when compile (e.g. if used with
+ // specific T).
+ // TODO(danilchap): Find a way to test they do not compile when thread
+ // annotation checks enabled.
+ template<typename T>
+ void access_var_no_annotate() {
+ var_thread_ = 42;
+ }
+
+ template<typename T>
+ void access_fun_no_annotate() {
+ function();
+ }
+
+ // Functions below should be able to compile.
+ void access_var_annotate_thread() {
+ RTC_DCHECK_RUN_ON(thread_);
+ var_thread_ = 42;
+ }
+
+ void access_var_annotate_checker() {
+ RTC_DCHECK_RUN_ON(&checker_);
+ var_checker_ = 44;
+ }
+
+ void access_var_annotate_queue() {
+ RTC_DCHECK_RUN_ON(queue_);
+ var_queue_ = 46;
+ }
+
+ void access_fun_annotate() {
+ RTC_DCHECK_RUN_ON(thread_);
+ function();
+ }
+
+ void access_fun_and_var() {
+ RTC_DCHECK_RUN_ON(thread_);
+ fun_acccess_var();
+ }
+
+ private:
+ void function() RUN_ON(thread_) {}
+ void fun_acccess_var() RUN_ON(thread_) { var_thread_ = 13; }
+
+ rtc::Thread* thread_;
+ rtc::ThreadChecker checker_;
+ rtc::TaskQueue* queue_;
+
+ int var_thread_ ACCESS_ON(thread_);
+ int var_checker_ GUARDED_BY(checker_);
+ int var_queue_ ACCESS_ON(queue_);
+};
+
// Just in case we ever get lumped together with other compilation units.
#undef ENABLE_THREAD_CHECKER
« no previous file with comments | « webrtc/base/thread_checker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698