Revert "Preparation for ReceiveStatisticsProxy lock reduction."
This reverts commit 24eed2735b2135227bcfefbabf34a89f9a5fec99. Reason for revert: Speculative revert: breaks downstream project Original change's description: > Preparation for ReceiveStatisticsProxy lock reduction. > > Update tests to call VideoReceiveStream::GetStats() in the same or at > least similar way it gets called in production (construction thread, > same TQ/thread). > > Mapped out threads and context for ReceiveStatisticsProxy, > VideoQualityObserver and VideoReceiveStream. Added > follow-up TODOs for webrtc:11489. > > One functional change in ReceiveStatisticsProxy is that when sender > side RtcpPacketTypesCounterUpdated calls are made, the counter is > updated asynchronously since the sender calls the method on a different > thread than the receiver. > > Make CallClient::SendTask public to allow tests to run tasks in the > right context. CallClient already does this internally for GetStats. > > Remove 10 sec sleep in StopSendingKeyframeRequestsForInactiveStream. > > Bug: webrtc:11489 > Change-Id: Ib45bfc59d8472e9c5ea556e6ecf38298b8f14921 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/172847 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Magnus Flodman <mflodman@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#31008} TBR=mbonadei@webrtc.org,henrika@webrtc.org,kwiberg@webrtc.org,tommi@webrtc.org,juberti@webrtc.org,mflodman@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:11489 Change-Id: I48b8359cdb791bf22b1a2c2c43d46263b01e0d65 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173082 Reviewed-by: Artem Titov <titovartem@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31023}
This commit is contained in:
committed by
Mirko Bonadei
parent
7e60483915
commit
16cc9efd54
@ -26,39 +26,12 @@ rtc_library("repeating_task") {
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("pending_task_safety_flag") {
|
||||
sources = [
|
||||
"pending_task_safety_flag.cc",
|
||||
"pending_task_safety_flag.h",
|
||||
]
|
||||
deps = [
|
||||
"..:checks",
|
||||
"..:refcount",
|
||||
"..:thread_checker",
|
||||
"../../api:scoped_refptr",
|
||||
"../synchronization:sequence_checker",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_source_set("to_queued_task") {
|
||||
sources = [ "to_queued_task.h" ]
|
||||
deps = [ "../../api/task_queue" ]
|
||||
}
|
||||
|
||||
if (rtc_include_tests) {
|
||||
rtc_library("pending_task_safety_flag_unittests") {
|
||||
testonly = true
|
||||
sources = [ "pending_task_safety_flag_unittest.cc" ]
|
||||
deps = [
|
||||
":pending_task_safety_flag",
|
||||
":to_queued_task",
|
||||
"..:rtc_base_approved",
|
||||
"..:rtc_task_queue",
|
||||
"..:task_queue_for_test",
|
||||
"../../test:test_support",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("repeating_task_unittests") {
|
||||
testonly = true
|
||||
sources = [ "repeating_task_unittest.cc" ]
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// static
|
||||
PendingTaskSafetyFlag::Pointer PendingTaskSafetyFlag::Create() {
|
||||
return new rtc::RefCountedObject<PendingTaskSafetyFlag>();
|
||||
}
|
||||
|
||||
void PendingTaskSafetyFlag::SetNotAlive() {
|
||||
RTC_DCHECK_RUN_ON(&main_sequence_);
|
||||
alive_ = false;
|
||||
}
|
||||
|
||||
bool PendingTaskSafetyFlag::alive() const {
|
||||
RTC_DCHECK_RUN_ON(&main_sequence_);
|
||||
return alive_;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef RTC_BASE_TASK_UTILS_PENDING_TASK_SAFETY_FLAG_H_
|
||||
#define RTC_BASE_TASK_UTILS_PENDING_TASK_SAFETY_FLAG_H_
|
||||
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "rtc_base/synchronization/sequence_checker.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Use this flag to drop pending tasks that have been posted to the "main"
|
||||
// thread/TQ and end up running after the owning instance has been
|
||||
// deleted. The owning instance signals deletion by calling SetNotAlive() from
|
||||
// its destructor.
|
||||
//
|
||||
// When posting a task, post a copy (capture by-value in a lambda) of the flag
|
||||
// instance and before performing the work, check the |alive()| state. Abort if
|
||||
// alive() returns |false|:
|
||||
//
|
||||
// // Running outside of the main thread.
|
||||
// my_task_queue_->PostTask(ToQueuedTask(
|
||||
// [safety = pending_task_safety_flag_, this]() {
|
||||
// // Now running on the main thread.
|
||||
// if (!safety->alive())
|
||||
// return;
|
||||
// MyMethod();
|
||||
// }));
|
||||
//
|
||||
// Note that checking the state only works on the construction/destruction
|
||||
// thread of the ReceiveStatisticsProxy instance.
|
||||
class PendingTaskSafetyFlag : public rtc::RefCountInterface {
|
||||
public:
|
||||
using Pointer = rtc::scoped_refptr<PendingTaskSafetyFlag>;
|
||||
static Pointer Create();
|
||||
|
||||
~PendingTaskSafetyFlag() = default;
|
||||
|
||||
void SetNotAlive();
|
||||
bool alive() const;
|
||||
|
||||
protected:
|
||||
PendingTaskSafetyFlag() = default;
|
||||
|
||||
private:
|
||||
bool alive_ = true;
|
||||
SequenceChecker main_sequence_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // RTC_BASE_TASK_UTILS_PENDING_TASK_SAFETY_FLAG_H_
|
||||
@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::MockFunction;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
} // namespace
|
||||
|
||||
TEST(PendingTaskSafetyFlagTest, Basic) {
|
||||
PendingTaskSafetyFlag::Pointer safety_flag;
|
||||
{
|
||||
// Scope for the |owner| instance.
|
||||
class Owner {
|
||||
public:
|
||||
Owner() = default;
|
||||
~Owner() { flag_->SetNotAlive(); }
|
||||
|
||||
PendingTaskSafetyFlag::Pointer flag_{PendingTaskSafetyFlag::Create()};
|
||||
} owner;
|
||||
EXPECT_TRUE(owner.flag_->alive());
|
||||
safety_flag = owner.flag_;
|
||||
EXPECT_TRUE(safety_flag->alive());
|
||||
}
|
||||
EXPECT_FALSE(safety_flag->alive());
|
||||
}
|
||||
|
||||
TEST(PendingTaskSafetyFlagTest, PendingTaskSuccess) {
|
||||
TaskQueueForTest tq1("OwnerHere");
|
||||
TaskQueueForTest tq2("OwnerNotHere");
|
||||
|
||||
class Owner {
|
||||
public:
|
||||
Owner() : tq_main_(TaskQueueBase::Current()) { RTC_DCHECK(tq_main_); }
|
||||
~Owner() {
|
||||
RTC_DCHECK(tq_main_->IsCurrent());
|
||||
flag_->SetNotAlive();
|
||||
}
|
||||
|
||||
void DoStuff() {
|
||||
RTC_DCHECK(!tq_main_->IsCurrent());
|
||||
tq_main_->PostTask(ToQueuedTask([safe = flag_, this]() {
|
||||
if (!safe->alive())
|
||||
return;
|
||||
stuff_done_ = true;
|
||||
}));
|
||||
}
|
||||
|
||||
bool stuff_done() const { return stuff_done_; }
|
||||
|
||||
private:
|
||||
TaskQueueBase* const tq_main_;
|
||||
bool stuff_done_ = false;
|
||||
PendingTaskSafetyFlag::Pointer flag_{PendingTaskSafetyFlag::Create()};
|
||||
};
|
||||
|
||||
std::unique_ptr<Owner> owner;
|
||||
tq1.SendTask(
|
||||
[&owner]() {
|
||||
owner.reset(new Owner());
|
||||
EXPECT_FALSE(owner->stuff_done());
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
ASSERT_TRUE(owner);
|
||||
tq2.SendTask([&owner]() { owner->DoStuff(); }, RTC_FROM_HERE);
|
||||
tq1.SendTask(
|
||||
[&owner]() {
|
||||
EXPECT_TRUE(owner->stuff_done());
|
||||
owner.reset();
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
ASSERT_FALSE(owner);
|
||||
}
|
||||
|
||||
TEST(PendingTaskSafetyFlagTest, PendingTaskDropped) {
|
||||
TaskQueueForTest tq1("OwnerHere");
|
||||
TaskQueueForTest tq2("OwnerNotHere");
|
||||
|
||||
class Owner {
|
||||
public:
|
||||
explicit Owner(bool* stuff_done)
|
||||
: tq_main_(TaskQueueBase::Current()), stuff_done_(stuff_done) {
|
||||
RTC_DCHECK(tq_main_);
|
||||
*stuff_done_ = false;
|
||||
}
|
||||
~Owner() {
|
||||
RTC_DCHECK(tq_main_->IsCurrent());
|
||||
flag_->SetNotAlive();
|
||||
}
|
||||
|
||||
void DoStuff() {
|
||||
RTC_DCHECK(!tq_main_->IsCurrent());
|
||||
tq_main_->PostTask(ToQueuedTask([safe = flag_, this]() {
|
||||
if (!safe->alive())
|
||||
return;
|
||||
*stuff_done_ = true;
|
||||
}));
|
||||
}
|
||||
|
||||
private:
|
||||
TaskQueueBase* const tq_main_;
|
||||
bool* const stuff_done_;
|
||||
PendingTaskSafetyFlag::Pointer flag_{PendingTaskSafetyFlag::Create()};
|
||||
};
|
||||
|
||||
std::unique_ptr<Owner> owner;
|
||||
bool stuff_done = false;
|
||||
tq1.SendTask([&owner, &stuff_done]() { owner.reset(new Owner(&stuff_done)); },
|
||||
RTC_FROM_HERE);
|
||||
ASSERT_TRUE(owner);
|
||||
// Queue up a task on tq1 that will execute before the 'DoStuff' task
|
||||
// can, and delete the |owner| before the 'stuff' task can execute.
|
||||
rtc::Event blocker;
|
||||
tq1.PostTask([&blocker, &owner]() {
|
||||
blocker.Wait(rtc::Event::kForever);
|
||||
owner.reset();
|
||||
});
|
||||
|
||||
// Queue up a DoStuff...
|
||||
tq2.SendTask([&owner]() { owner->DoStuff(); }, RTC_FROM_HERE);
|
||||
|
||||
ASSERT_TRUE(owner);
|
||||
blocker.Set();
|
||||
|
||||
// Run an empty task on tq1 to flush all the queued tasks.
|
||||
tq1.SendTask([]() {}, RTC_FROM_HERE);
|
||||
ASSERT_FALSE(owner);
|
||||
EXPECT_FALSE(stuff_done);
|
||||
}
|
||||
} // namespace webrtc
|
||||
Reference in New Issue
Block a user