diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/base/sequence_checker.h | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/sequence_checker.h')
-rw-r--r-- | chromium/base/sequence_checker.h | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/chromium/base/sequence_checker.h b/chromium/base/sequence_checker.h index 3ab8768a1bb..50a548a759c 100644 --- a/chromium/base/sequence_checker.h +++ b/chromium/base/sequence_checker.h @@ -10,6 +10,10 @@ #include "base/strings/string_piece.h" #include "build/build_config.h" +#if DCHECK_IS_ON() +#include "base/debug/stack_trace.h" +#endif + // SequenceChecker is a helper class used to help verify that some methods of a // class are called sequentially (for thread-safety). It supports thread safety // annotations (see base/thread_annotations.h). @@ -22,12 +26,18 @@ // ThreadChecker should only be used for classes that are truly thread-affine // (use thread-local-storage or a third-party API that does). // +// Debugging: +// If SequenceChecker::EnableStackLogging() is called beforehand, then when +// SequenceChecker fails, in addition to crashing with a stack trace of where +// the violation occurred, it will also dump a stack trace of where the +// checker was bound to a sequence. +// // Usage: // class MyClass { // public: // MyClass() { -// // It's sometimes useful to detach on construction for objects that are -// // constructed in one place and forever after used from another +// // Detaching on construction is necessary for objects that are +// // constructed on one sequence and forever after used from another // // sequence. // DETACH_FROM_SEQUENCE(my_sequence_checker_); // } @@ -88,10 +98,13 @@ namespace base { // // Note: You should almost always use the SequenceChecker class (through the // above macros) to get the right version for your build configuration. -// Note: This is only a check, not a "lock". It is marked "LOCKABLE" only in -// order to support thread_annotations.h. -class LOCKABLE SequenceCheckerDoNothing { +// Note: This is marked with "context" capability in order to support +// thread_annotations.h. +class THREAD_ANNOTATION_ATTRIBUTE__(capability("context")) + SequenceCheckerDoNothing { public: + static void EnableStackLogging() {} + SequenceCheckerDoNothing() = default; // Moving between matching sequences is allowed to help classes with @@ -102,35 +115,44 @@ class LOCKABLE SequenceCheckerDoNothing { SequenceCheckerDoNothing(const SequenceCheckerDoNothing&) = delete; SequenceCheckerDoNothing& operator=(const SequenceCheckerDoNothing&) = delete; - bool CalledOnValidSequence() const WARN_UNUSED_RESULT { return true; } + bool CalledOnValidSequence(void* = nullptr) const WARN_UNUSED_RESULT { + return true; + } void DetachFromSequence() {} }; #if DCHECK_IS_ON() -class SequenceChecker : public SequenceCheckerImpl { -}; +using SequenceChecker = SequenceCheckerImpl; #else -class SequenceChecker : public SequenceCheckerDoNothing { -}; +using SequenceChecker = SequenceCheckerDoNothing; #endif // DCHECK_IS_ON() +#if DCHECK_IS_ON() class SCOPED_LOCKABLE ScopedValidateSequenceChecker { public: explicit ScopedValidateSequenceChecker(const SequenceChecker& checker) EXCLUSIVE_LOCK_FUNCTION(checker) { - DCHECK(checker.CalledOnValidSequence()); + std::unique_ptr<debug::StackTrace> bound_at; + DCHECK(checker.CalledOnValidSequence(&bound_at)) + << (bound_at ? "\nWas attached to sequence at:\n" + bound_at->ToString() + : ""); } explicit ScopedValidateSequenceChecker(const SequenceChecker& checker, const StringPiece& msg) EXCLUSIVE_LOCK_FUNCTION(checker) { - DCHECK(checker.CalledOnValidSequence()) << msg; + std::unique_ptr<debug::StackTrace> bound_at; + DCHECK(checker.CalledOnValidSequence(&bound_at)) + << msg + << (bound_at ? "\nWas attached to sequence at:\n" + bound_at->ToString() + : ""); } ~ScopedValidateSequenceChecker() UNLOCK_FUNCTION() {} private: }; +#endif } // namespace base |