зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1832751 - cherry-pick upstream libwebrtc commit 3da04a93cd. r=webrtc-reviewers,mjf
Upstream commit: https://webrtc.googlesource.com/src/+/3da04a93cd18dc7b65c6756910cc8a9cbf20fb8c Allow SequenceChecker to be initialized detached. The motivation for this is to not have to implement this pattern: foo.h: class Foo { public: Foo(); private: SequenceChecker checker_; }; foo.cc: Foo::Foo() { checker_.Detach(); } And instead be able to do this inline in the .h file: class Foo { public: Foo(); private: SequenceChecker checker_{SequenceChecker::kDetached}; }; Bug: none Change-Id: Idd7ca82d15c2f77f3aaccf26f1943a49f4b40661 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/298445 Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39616} Differential Revision: https://phabricator.services.mozilla.com/D177874
This commit is contained in:
Родитель
6af5555c16
Коммит
8824e00492
|
@ -44,6 +44,11 @@ class RTC_LOCKABLE SequenceChecker
|
||||||
using Impl = webrtc_sequence_checker_internal::SequenceCheckerDoNothing;
|
using Impl = webrtc_sequence_checker_internal::SequenceCheckerDoNothing;
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
|
enum InitialState : bool { kDetached = false, kAttached = true };
|
||||||
|
|
||||||
|
explicit SequenceChecker(InitialState initial_state = kAttached)
|
||||||
|
: Impl(initial_state) {}
|
||||||
|
|
||||||
// Returns true if sequence checker is attached to the current sequence.
|
// Returns true if sequence checker is attached to the current sequence.
|
||||||
bool IsCurrent() const { return Impl::IsCurrent(); }
|
bool IsCurrent() const { return Impl::IsCurrent(); }
|
||||||
// Detaches checker from sequence to which it is attached. Next attempt
|
// Detaches checker from sequence to which it is attached. Next attempt
|
||||||
|
|
|
@ -122,8 +122,7 @@ TEST(SequenceCheckerTest, DetachFromTaskQueueInDebug) {
|
||||||
TEST(SequenceCheckerTest, ExpectationToString) {
|
TEST(SequenceCheckerTest, ExpectationToString) {
|
||||||
TaskQueueForTest queue1;
|
TaskQueueForTest queue1;
|
||||||
|
|
||||||
SequenceChecker sequence_checker;
|
SequenceChecker sequence_checker(SequenceChecker::kDetached);
|
||||||
sequence_checker.Detach();
|
|
||||||
|
|
||||||
rtc::Event blocker;
|
rtc::Event blocker;
|
||||||
queue1.PostTask([&blocker, &sequence_checker]() {
|
queue1.PostTask([&blocker, &sequence_checker]() {
|
||||||
|
@ -149,6 +148,24 @@ TEST(SequenceCheckerTest, ExpectationToString) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(SequenceCheckerTest, InitiallyDetached) {
|
||||||
|
TaskQueueForTest queue1;
|
||||||
|
|
||||||
|
SequenceChecker sequence_checker(SequenceChecker::kDetached);
|
||||||
|
|
||||||
|
rtc::Event blocker;
|
||||||
|
queue1.PostTask([&blocker, &sequence_checker]() {
|
||||||
|
EXPECT_TRUE(sequence_checker.IsCurrent());
|
||||||
|
blocker.Set();
|
||||||
|
});
|
||||||
|
|
||||||
|
blocker.Wait(rtc::Event::kForever);
|
||||||
|
|
||||||
|
#if RTC_DCHECK_IS_ON
|
||||||
|
EXPECT_FALSE(sequence_checker.IsCurrent());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
class TestAnnotations {
|
class TestAnnotations {
|
||||||
public:
|
public:
|
||||||
TestAnnotations() : test_var_(false) {}
|
TestAnnotations() : test_var_(false) {}
|
||||||
|
|
|
@ -33,8 +33,8 @@ const void* GetSystemQueueRef() {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
SequenceCheckerImpl::SequenceCheckerImpl()
|
SequenceCheckerImpl::SequenceCheckerImpl(bool attach_to_current_thread)
|
||||||
: attached_(true),
|
: attached_(attach_to_current_thread),
|
||||||
valid_thread_(rtc::CurrentThreadRef()),
|
valid_thread_(rtc::CurrentThreadRef()),
|
||||||
valid_queue_(TaskQueueBase::Current()),
|
valid_queue_(TaskQueueBase::Current()),
|
||||||
valid_system_queue_(GetSystemQueueRef()) {}
|
valid_system_queue_(GetSystemQueueRef()) {}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace webrtc_sequence_checker_internal {
|
||||||
// right version for your build configuration.
|
// right version for your build configuration.
|
||||||
class RTC_EXPORT SequenceCheckerImpl {
|
class RTC_EXPORT SequenceCheckerImpl {
|
||||||
public:
|
public:
|
||||||
SequenceCheckerImpl();
|
explicit SequenceCheckerImpl(bool attach_to_current_thread);
|
||||||
~SequenceCheckerImpl() = default;
|
~SequenceCheckerImpl() = default;
|
||||||
|
|
||||||
bool IsCurrent() const;
|
bool IsCurrent() const;
|
||||||
|
@ -59,6 +59,7 @@ class RTC_EXPORT SequenceCheckerImpl {
|
||||||
// right version for your build configuration.
|
// right version for your build configuration.
|
||||||
class SequenceCheckerDoNothing {
|
class SequenceCheckerDoNothing {
|
||||||
public:
|
public:
|
||||||
|
explicit SequenceCheckerDoNothing(bool attach_to_current_thread) {}
|
||||||
bool IsCurrent() const { return true; }
|
bool IsCurrent() const { return true; }
|
||||||
void Detach() {}
|
void Detach() {}
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче