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 <eshr@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37678}
This commit is contained in:
Danil Chapovalov 2022-08-03 13:32:40 +02:00 committed by WebRTC LUCI CQ
parent 70ed471836
commit 07eaddf939
2 changed files with 7 additions and 13 deletions

View file

@ -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_

View file

@ -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).