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

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: examples rewritten, few tests added 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
« webrtc/base/thread_checker.h ('K') | « 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..48c4cd1960d28ebce9138144c5ff5d891e564c4d 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,59 @@ TEST(ThreadCheckerTest, DetachFromThreadInRelease) {
#endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER
+class ThreadAnnotateTest {
+ public:
+ rtc::Thread* thread;
tommi 2016/05/19 08:26:14 move these member variables to the bottom of the c
danilchap 2016/05/19 11:45:29 Done.
+ rtc::ThreadChecker checker;
+ rtc::TaskQueue* queue;
+
+ int var_thread ACCESS_ON(thread);
+ int var_checker ACCESS_ON(checker);
+ int var_queue ACCESS_ON(queue);
+ void function() RUN_ON(thread) {}
+ void fun_acccess_var() RUN_ON(thread) { var_thread = 13; }
+
+ // 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();
+ }
+};
+
// Just in case we ever get lumped together with other compilation units.
#undef ENABLE_THREAD_CHECKER
« webrtc/base/thread_checker.h ('K') | « webrtc/base/thread_checker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698