Allow recursive check for RTC_DCHECK_RUN_ON macro

instead of using Lock/Unlock attributes, use Assert attribute to annotate code is running on certain task queue or thread.

Such check better matches what is checked, in particular allows to
recheck (and thus better document) currently used task queue

Bug: None
Change-Id: I5bc1c397efbc8342cf7915093b578bb015c85651
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269381
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37619}
This commit is contained in:
Danil Chapovalov
2022-07-25 15:58:28 +02:00
committed by WebRTC LUCI CQ
parent a3f2e72008
commit 6e7c2685e3
15 changed files with 68 additions and 73 deletions

View File

@ -19,9 +19,21 @@
#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).
@ -63,22 +75,6 @@ class SequenceCheckerDoNothing {
void Detach() {}
};
// Helper class used by RTC_DCHECK_RUN_ON (see example usage below).
class RTC_SCOPED_LOCKABLE SequenceCheckerScope {
public:
template <typename ThreadLikeObject>
explicit SequenceCheckerScope(const ThreadLikeObject* thread_like_object)
RTC_EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {}
SequenceCheckerScope(const SequenceCheckerScope&) = delete;
SequenceCheckerScope& operator=(const SequenceCheckerScope&) = delete;
~SequenceCheckerScope() RTC_UNLOCK_FUNCTION() {}
template <typename ThreadLikeObject>
static bool IsCurrent(const ThreadLikeObject* thread_like_object) {
return thread_like_object->IsCurrent();
}
};
std::string ExpectationToString(const SequenceCheckerImpl* checker);
// Catch-all implementation for types other than explicitly supported above.