From 07eaddf93932e7aaf16ca6a5bed3aeb59bbaae8e Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Wed, 3 Aug 2022 13:32:40 +0200 Subject: [PATCH] Inline assert in RTC_DCHECK_RUN_ON macro clangd ignores ASSERT_EXCLUSIVE_LOCK macro attached to an inline function in header, thus IDEs relying on clangd issue false positive warnings about members acceesses without the check of the current sequence. Attaching assert attribute to an inlined lambda function seems to solve that issue Bug: None Change-Id: I6199fee26061aa4223f2e3ea7b7b14bb5820c0bc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/270480 Reviewed-by: Evan Shrubsole Reviewed-by: Tomas Gunnarsson Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#37678} --- api/sequence_checker.h | 8 +++++++- rtc_base/synchronization/sequence_checker_internal.h | 12 ------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/api/sequence_checker.h b/api/sequence_checker.h index b9f466b9a7..a79d04f61f 100644 --- a/api/sequence_checker.h +++ b/api/sequence_checker.h @@ -107,9 +107,15 @@ class RTC_LOCKABLE SequenceChecker #define RTC_RUN_ON(x) \ RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) +// Checks current code is running on the desired sequence. +// +// First statement validates it is running on the sequence `x`. +// Second statement annotates for the thread safety analyzer the check was done. +// Such annotation has to be attached to a function, and that function has to be +// called. Thus current implementation creates a noop lambda and calls it. #define RTC_DCHECK_RUN_ON(x) \ RTC_DCHECK((x)->IsCurrent()) \ << webrtc::webrtc_sequence_checker_internal::ExpectationToString(x); \ - webrtc::webrtc_sequence_checker_internal::AssertHeld(x) + []() RTC_ASSERT_EXCLUSIVE_LOCK(x) {}() #endif // API_SEQUENCE_CHECKER_H_ diff --git a/rtc_base/synchronization/sequence_checker_internal.h b/rtc_base/synchronization/sequence_checker_internal.h index 3457765216..be89133a69 100644 --- a/rtc_base/synchronization/sequence_checker_internal.h +++ b/rtc_base/synchronization/sequence_checker_internal.h @@ -19,21 +19,9 @@ #include "rtc_base/system/rtc_export.h" #include "rtc_base/thread_annotations.h" -namespace rtc { -class TaskQueue; -} // namespace rtc - namespace webrtc { -class SequenceChecker; namespace webrtc_sequence_checker_internal { -inline void AssertHeld(const SequenceChecker* checker) - RTC_ASSERT_EXCLUSIVE_LOCK(checker) {} -inline void AssertHeld(const TaskQueueBase* task_queue) - RTC_ASSERT_EXCLUSIVE_LOCK(task_queue) {} -inline void AssertHeld(const rtc::TaskQueue* task_queue) - RTC_ASSERT_EXCLUSIVE_LOCK(task_queue) {} - // Real implementation of SequenceChecker, for use in debug mode, or // for temporary use in release mode (e.g. to RTC_CHECK on a threading issue // seen only in the wild).