Add diagnostic printout to RTC_DCHECK_RUN_ON.
When using a SequenceChecker, this adds a bit more information about why the check failed. Example (The "Expects" line is new): # Fatal error in: foo.cc, line 380 # last system error: 0 # Check failed: (&thread_checker_)->IsCurrent() # Expects: System queue: 0x7fff69541330, TaskQueue: 0x101804370 (not current), Thread: 0x10053cdc0 Bug: none Change-Id: I3743e1d80f369f15219de5946e9e081f998b9b17 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176569 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31466}
This commit is contained in:
committed by
Commit Bot
parent
09eb6e249d
commit
4d177eb1bd
@ -10,6 +10,8 @@
|
||||
#ifndef RTC_BASE_SYNCHRONIZATION_SEQUENCE_CHECKER_H_
|
||||
#define RTC_BASE_SYNCHRONIZATION_SEQUENCE_CHECKER_H_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/platform_thread_types.h"
|
||||
@ -34,6 +36,11 @@ class RTC_EXPORT SequenceCheckerImpl {
|
||||
// used exclusively on another thread.
|
||||
void Detach();
|
||||
|
||||
// Returns a string that is formatted to match with the error string printed
|
||||
// by RTC_CHECK() when a condition is not met.
|
||||
// This is used in conjunction with the RTC_DCHECK_RUN_ON() macro.
|
||||
std::string ExpectationToString() const;
|
||||
|
||||
private:
|
||||
rtc::CriticalSection lock_;
|
||||
// These are mutable so that IsCurrent can set them.
|
||||
@ -162,8 +169,19 @@ class RTC_SCOPED_LOCKABLE SequenceCheckerScope {
|
||||
#define RTC_RUN_ON(x) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x))
|
||||
|
||||
namespace webrtc {
|
||||
std::string ExpectationToString(const webrtc::SequenceChecker* checker);
|
||||
|
||||
// Catch-all implementation for types other than explicitly supported above.
|
||||
template <typename ThreadLikeObject>
|
||||
std::string ExpectationToString(const ThreadLikeObject*) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#define RTC_DCHECK_RUN_ON(x) \
|
||||
webrtc::webrtc_seq_check_impl::SequenceCheckerScope seq_check_scope(x); \
|
||||
RTC_DCHECK((x)->IsCurrent())
|
||||
RTC_DCHECK((x)->IsCurrent()) << webrtc::ExpectationToString(x)
|
||||
|
||||
#endif // RTC_BASE_SYNCHRONIZATION_SEQUENCE_CHECKER_H_
|
||||
|
||||
Reference in New Issue
Block a user