Mark rtc::Thread's versions of PostTask/PostDelayedTask deprecated.
Because rtc::Thread inherits from TaskQueueBase, it already implements a pair of PostTask/PostDelayedTask methods that we want to keep. But in addition to those, rtc::Thread defines its own PostTask/PostDelayedTask using templates. These are the versions that we want to deprecate. They were originally implemented prior to rtc::Thread inheriting from TaskQueueBase. We want to deprecate them because... - We don't want to have multiple code paths that do the same thing. - We want to move away from rtc::Thread to TaskQueueBase long-term. - These versions are not overridable in Chromium. - These versions don't have high/low precision versions of PDT. Helper methods are added to rtc::Thread so that callers don't have to wrap every lambda in webrtc::ToQueuedTask() and update dependencies. Bug: webrtc:13582 Change-Id: I58702c53f4cb3705681bd9f1ea16b7aaa5052c18 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247660 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Markus Handell <handellm@google.com> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35750}
This commit is contained in:
parent
c065e739e2
commit
2deee4bbb2
@ -41,7 +41,6 @@ namespace {
|
||||
#define RUN_ON_VOIP_THREAD(method, ...) \
|
||||
if (!voip_thread_->IsCurrent()) { \
|
||||
voip_thread_->PostTask( \
|
||||
RTC_FROM_HERE, \
|
||||
std::bind(&AndroidVoipClient::method, this, ##__VA_ARGS__)); \
|
||||
return; \
|
||||
} \
|
||||
@ -228,7 +227,7 @@ void AndroidVoipClient::SetEncoder(
|
||||
const std::string& chosen_encoder =
|
||||
webrtc::JavaToNativeString(env, j_encoder_string);
|
||||
voip_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, chosen_encoder] { SetEncoder(chosen_encoder); });
|
||||
[this, chosen_encoder] { SetEncoder(chosen_encoder); });
|
||||
}
|
||||
|
||||
void AndroidVoipClient::SetDecoders(const std::vector<std::string>& decoders) {
|
||||
@ -258,7 +257,7 @@ void AndroidVoipClient::SetDecoders(
|
||||
webrtc::JavaListToNativeVector<std::string, jstring>(
|
||||
env, j_decoder_strings, &webrtc::JavaToNativeString);
|
||||
voip_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, chosen_decoders] { SetDecoders(chosen_decoders); });
|
||||
[this, chosen_decoders] { SetDecoders(chosen_decoders); });
|
||||
}
|
||||
|
||||
void AndroidVoipClient::SetLocalAddress(const std::string& ip_address,
|
||||
@ -275,7 +274,7 @@ void AndroidVoipClient::SetLocalAddress(
|
||||
jint j_port_number_int) {
|
||||
const std::string& ip_address =
|
||||
webrtc::JavaToNativeString(env, j_ip_address_string);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE, [this, ip_address, j_port_number_int] {
|
||||
voip_thread_->PostTask([this, ip_address, j_port_number_int] {
|
||||
SetLocalAddress(ip_address, j_port_number_int);
|
||||
});
|
||||
}
|
||||
@ -294,7 +293,7 @@ void AndroidVoipClient::SetRemoteAddress(
|
||||
jint j_port_number_int) {
|
||||
const std::string& ip_address =
|
||||
webrtc::JavaToNativeString(env, j_ip_address_string);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE, [this, ip_address, j_port_number_int] {
|
||||
voip_thread_->PostTask([this, ip_address, j_port_number_int] {
|
||||
SetRemoteAddress(ip_address, j_port_number_int);
|
||||
});
|
||||
}
|
||||
@ -431,10 +430,9 @@ bool AndroidVoipClient::SendRtp(const uint8_t* packet,
|
||||
size_t length,
|
||||
const webrtc::PacketOptions& options) {
|
||||
std::vector<uint8_t> packet_copy(packet, packet + length);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this, packet_copy = std::move(packet_copy)] {
|
||||
SendRtpPacket(packet_copy);
|
||||
});
|
||||
voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
|
||||
SendRtpPacket(packet_copy);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -450,10 +448,9 @@ void AndroidVoipClient::SendRtcpPacket(
|
||||
|
||||
bool AndroidVoipClient::SendRtcp(const uint8_t* packet, size_t length) {
|
||||
std::vector<uint8_t> packet_copy(packet, packet + length);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this, packet_copy = std::move(packet_copy)] {
|
||||
SendRtcpPacket(packet_copy);
|
||||
});
|
||||
voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
|
||||
SendRtcpPacket(packet_copy);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -476,10 +473,9 @@ void AndroidVoipClient::OnSignalReadRTPPacket(rtc::AsyncPacketSocket* socket,
|
||||
const rtc::SocketAddress& addr,
|
||||
const int64_t& timestamp) {
|
||||
std::vector<uint8_t> packet_copy(rtp_packet, rtp_packet + size);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this, packet_copy = std::move(packet_copy)] {
|
||||
ReadRTPPacket(packet_copy);
|
||||
});
|
||||
voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
|
||||
ReadRTPPacket(packet_copy);
|
||||
});
|
||||
}
|
||||
|
||||
void AndroidVoipClient::ReadRTCPPacket(
|
||||
@ -502,10 +498,9 @@ void AndroidVoipClient::OnSignalReadRTCPPacket(rtc::AsyncPacketSocket* socket,
|
||||
const rtc::SocketAddress& addr,
|
||||
const int64_t& timestamp) {
|
||||
std::vector<uint8_t> packet_copy(rtcp_packet, rtcp_packet + size);
|
||||
voip_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this, packet_copy = std::move(packet_copy)] {
|
||||
ReadRTCPPacket(packet_copy);
|
||||
});
|
||||
voip_thread_->PostTask([this, packet_copy = std::move(packet_copy)] {
|
||||
ReadRTCPPacket(packet_copy);
|
||||
});
|
||||
}
|
||||
|
||||
static jlong JNI_VoipClient_CreateClient(
|
||||
|
||||
@ -138,7 +138,7 @@ class WgcCapturerWinTest : public ::testing::TestWithParam<CaptureType>,
|
||||
}
|
||||
|
||||
void StartWindowThreadMessageLoop() {
|
||||
window_thread_->PostTask(RTC_FROM_HERE, [this]() {
|
||||
window_thread_->PostTask([this]() {
|
||||
MSG msg;
|
||||
BOOL gm;
|
||||
while ((gm = ::GetMessage(&msg, NULL, 0, 0)) != 0 && gm != -1) {
|
||||
|
||||
@ -39,7 +39,7 @@ std::unique_ptr<rtc::Thread> SetUpUnresponsiveWindow(std::mutex& mtx,
|
||||
|
||||
// Intentionally create a deadlock to cause the window to become unresponsive.
|
||||
mtx.lock();
|
||||
window_thread->PostTask(RTC_FROM_HERE, [&mtx]() {
|
||||
window_thread->PostTask([&mtx]() {
|
||||
mtx.lock();
|
||||
mtx.unlock();
|
||||
});
|
||||
|
||||
@ -499,7 +499,7 @@ class ChannelTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||
explicit ScopedCallThread(FunctorT&& functor)
|
||||
: thread_(rtc::Thread::Create()) {
|
||||
thread_->Start();
|
||||
thread_->PostTask(RTC_FROM_HERE, std::forward<FunctorT>(functor));
|
||||
thread_->PostTask(std::forward<FunctorT>(functor));
|
||||
}
|
||||
|
||||
~ScopedCallThread() { thread_->Stop(); }
|
||||
@ -1237,12 +1237,12 @@ class ChannelTest : public ::testing::Test, public sigslot::has_slots<> {
|
||||
EXPECT_FALSE(media_channel1()->ready_to_send());
|
||||
|
||||
network_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this] { channel1_->OnTransportReadyToSend(true); });
|
||||
[this] { channel1_->OnTransportReadyToSend(true); });
|
||||
WaitForThreads();
|
||||
EXPECT_TRUE(media_channel1()->ready_to_send());
|
||||
|
||||
network_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this] { channel1_->OnTransportReadyToSend(false); });
|
||||
[this] { channel1_->OnTransportReadyToSend(false); });
|
||||
WaitForThreads();
|
||||
EXPECT_FALSE(media_channel1()->ready_to_send());
|
||||
}
|
||||
|
||||
@ -1252,7 +1252,6 @@ void RTCStatsCollector::GetStatsReportInternal(
|
||||
network_report_event_.Reset();
|
||||
rtc::scoped_refptr<RTCStatsCollector> collector(this);
|
||||
network_thread_->PostTask(
|
||||
RTC_FROM_HERE,
|
||||
[collector, sctp_transport_name = pc_->sctp_transport_name(),
|
||||
timestamp_us]() mutable {
|
||||
collector->ProducePartialResultsOnNetworkThread(
|
||||
@ -1341,7 +1340,7 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
|
||||
network_report_event_.Set();
|
||||
rtc::scoped_refptr<RTCStatsCollector> collector(this);
|
||||
signaling_thread_->PostTask(
|
||||
RTC_FROM_HERE, [collector] { collector->MergeNetworkReport_s(); });
|
||||
[collector] { collector->MergeNetworkReport_s(); });
|
||||
}
|
||||
|
||||
void RTCStatsCollector::ProducePartialResultsOnNetworkThreadImpl(
|
||||
|
||||
@ -790,7 +790,10 @@ rtc_library("threading") {
|
||||
"thread.h",
|
||||
"thread_message.h",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||
"//third_party/abseil-cpp/absl/base:core_headers",
|
||||
]
|
||||
deps = [
|
||||
":async_resolver_interface",
|
||||
":atomicops",
|
||||
|
||||
@ -87,17 +87,15 @@ class OperationTracker {
|
||||
Event* operation_complete_event,
|
||||
std::function<void()> callback) {
|
||||
Thread* current_thread = Thread::Current();
|
||||
background_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, current_thread, unblock_operation_event,
|
||||
operation_complete_event, callback]() {
|
||||
unblock_operation_event->Wait(Event::kForever);
|
||||
current_thread->PostTask(
|
||||
RTC_FROM_HERE, [this, operation_complete_event, callback]() {
|
||||
completed_operation_events_.push_back(operation_complete_event);
|
||||
operation_complete_event->Set();
|
||||
callback();
|
||||
});
|
||||
});
|
||||
background_thread_->PostTask([this, current_thread, unblock_operation_event,
|
||||
operation_complete_event, callback]() {
|
||||
unblock_operation_event->Wait(Event::kForever);
|
||||
current_thread->PostTask([this, operation_complete_event, callback]() {
|
||||
completed_operation_events_.push_back(operation_complete_event);
|
||||
operation_complete_event->Set();
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<Thread> background_thread_;
|
||||
@ -118,19 +116,17 @@ class OperationTrackerProxy {
|
||||
|
||||
std::unique_ptr<Event> Initialize() {
|
||||
std::unique_ptr<Event> event = std::make_unique<Event>();
|
||||
operations_chain_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, event_ptr = event.get()]() {
|
||||
operation_tracker_ = std::make_unique<OperationTracker>();
|
||||
operations_chain_ = OperationsChain::Create();
|
||||
event_ptr->Set();
|
||||
});
|
||||
operations_chain_thread_->PostTask([this, event_ptr = event.get()]() {
|
||||
operation_tracker_ = std::make_unique<OperationTracker>();
|
||||
operations_chain_ = OperationsChain::Create();
|
||||
event_ptr->Set();
|
||||
});
|
||||
return event;
|
||||
}
|
||||
|
||||
void SetOnChainEmptyCallback(std::function<void()> on_chain_empty_callback) {
|
||||
Event event;
|
||||
operations_chain_thread_->PostTask(
|
||||
RTC_FROM_HERE,
|
||||
[this, &event,
|
||||
on_chain_empty_callback = std::move(on_chain_empty_callback)]() {
|
||||
operations_chain_->SetOnChainEmptyCallback(
|
||||
@ -143,22 +139,20 @@ class OperationTrackerProxy {
|
||||
bool IsEmpty() {
|
||||
Event event;
|
||||
bool is_empty = false;
|
||||
operations_chain_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, &event, &is_empty]() {
|
||||
is_empty = operations_chain_->IsEmpty();
|
||||
event.Set();
|
||||
});
|
||||
operations_chain_thread_->PostTask([this, &event, &is_empty]() {
|
||||
is_empty = operations_chain_->IsEmpty();
|
||||
event.Set();
|
||||
});
|
||||
event.Wait(Event::kForever);
|
||||
return is_empty;
|
||||
}
|
||||
|
||||
std::unique_ptr<Event> ReleaseOperationChain() {
|
||||
std::unique_ptr<Event> event = std::make_unique<Event>();
|
||||
operations_chain_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this, event_ptr = event.get()]() {
|
||||
operations_chain_ = nullptr;
|
||||
event_ptr->Set();
|
||||
});
|
||||
operations_chain_thread_->PostTask([this, event_ptr = event.get()]() {
|
||||
operations_chain_ = nullptr;
|
||||
event_ptr->Set();
|
||||
});
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -166,8 +160,8 @@ class OperationTrackerProxy {
|
||||
std::unique_ptr<Event> PostSynchronousOperation() {
|
||||
std::unique_ptr<Event> operation_complete_event = std::make_unique<Event>();
|
||||
operations_chain_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, operation_complete_event_ptr =
|
||||
operation_complete_event.get()]() {
|
||||
[this,
|
||||
operation_complete_event_ptr = operation_complete_event.get()]() {
|
||||
operations_chain_->ChainOperation(
|
||||
operation_tracker_->BindSynchronousOperation(
|
||||
operation_complete_event_ptr));
|
||||
@ -181,7 +175,6 @@ class OperationTrackerProxy {
|
||||
Event* unblock_operation_event) {
|
||||
std::unique_ptr<Event> operation_complete_event = std::make_unique<Event>();
|
||||
operations_chain_thread_->PostTask(
|
||||
RTC_FROM_HERE,
|
||||
[this, unblock_operation_event,
|
||||
operation_complete_event_ptr = operation_complete_event.get()]() {
|
||||
operations_chain_->ChainOperation(
|
||||
|
||||
@ -79,13 +79,13 @@ void RTCCertificateGenerator::GenerateCertificateAsync(
|
||||
// Create a new `RTCCertificateGenerationTask` for this generation request. It
|
||||
// is reference counted and referenced by the message data, ensuring it lives
|
||||
// until the task has completed (independent of `RTCCertificateGenerator`).
|
||||
worker_thread_->PostTask(RTC_FROM_HERE, [key_params, expires_ms,
|
||||
signaling_thread = signaling_thread_,
|
||||
cb = callback]() {
|
||||
worker_thread_->PostTask([key_params, expires_ms,
|
||||
signaling_thread = signaling_thread_,
|
||||
cb = callback]() {
|
||||
scoped_refptr<RTCCertificate> certificate =
|
||||
RTCCertificateGenerator::GenerateCertificate(key_params, expires_ms);
|
||||
signaling_thread->PostTask(
|
||||
RTC_FROM_HERE, [cert = std::move(certificate), cb = std::move(cb)]() {
|
||||
[cert = std::move(certificate), cb = std::move(cb)]() {
|
||||
cert ? cb->OnSuccess(cert) : cb->OnFailure();
|
||||
});
|
||||
});
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#if defined(WEBRTC_POSIX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include "absl/base/attributes.h"
|
||||
#include "api/function_view.h"
|
||||
#include "api/task_queue/queued_task.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
@ -35,6 +36,7 @@
|
||||
#include "rtc_base/platform_thread_types.h"
|
||||
#include "rtc_base/socket_server.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "rtc_base/thread_message.h"
|
||||
|
||||
@ -454,26 +456,42 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
||||
// [&x, &y] { x.TrackComputations(y.Compute()); });
|
||||
//
|
||||
// TODO(https://crbug.com/webrtc/13582): Deprecate and remove in favor of the
|
||||
// PostTask() method inherited from TaskQueueBase. Stop using it inside
|
||||
// third_party/webrtc and add ABSL_DEPRECATED("bugs.webrtc.org/13582").
|
||||
// PostTask() method inherited from TaskQueueBase and template helpers defined
|
||||
// here in rtc::Thread for performing webrtc::ToQueuedTask(). Migration is
|
||||
// easy, just remove RTC_FROM_HERE like so:
|
||||
//
|
||||
// Before:
|
||||
// thread->PostTask(RTC_FROM_HERE, []() { printfln("wow"); });
|
||||
// After:
|
||||
// thread->PostTask([]() { printfln("wow"); });
|
||||
template <class FunctorT>
|
||||
void PostTask(const Location& posted_from, FunctorT&& functor) {
|
||||
void DEPRECATED_PostTask(const Location& posted_from, FunctorT&& functor) {
|
||||
Post(posted_from, GetPostTaskMessageHandler(), /*id=*/0,
|
||||
new rtc_thread_internal::MessageWithFunctor<FunctorT>(
|
||||
std::forward<FunctorT>(functor)));
|
||||
}
|
||||
// TODO(https://crbug.com/webrtc/13582): Deprecate and remove in favor of the
|
||||
// PostTask() method inherited from TaskQueueBase. Stop using it inside
|
||||
// third_party/webrtc and add ABSL_DEPRECATED("bugs.webrtc.org/13582").
|
||||
template <class FunctorT>
|
||||
void PostDelayedTask(const Location& posted_from,
|
||||
FunctorT&& functor,
|
||||
uint32_t milliseconds) {
|
||||
ABSL_DEPRECATED("bugs.webrtc.org/13582")
|
||||
void PostTask(const Location& posted_from, FunctorT&& functor) {
|
||||
DEPRECATED_PostTask(posted_from, std::forward<FunctorT>(functor));
|
||||
}
|
||||
template <class FunctorT>
|
||||
void DEPRECATED_PostDelayedTask(const Location& posted_from,
|
||||
FunctorT&& functor,
|
||||
uint32_t milliseconds) {
|
||||
PostDelayed(posted_from, milliseconds, GetPostTaskMessageHandler(),
|
||||
/*id=*/0,
|
||||
new rtc_thread_internal::MessageWithFunctor<FunctorT>(
|
||||
std::forward<FunctorT>(functor)));
|
||||
}
|
||||
template <class FunctorT>
|
||||
ABSL_DEPRECATED("bugs.webrtc.org/13582")
|
||||
void PostDelayedTask(const Location& posted_from,
|
||||
FunctorT&& functor,
|
||||
uint32_t milliseconds) {
|
||||
DEPRECATED_PostDelayedTask(posted_from, std::forward<FunctorT>(functor),
|
||||
milliseconds);
|
||||
}
|
||||
|
||||
// From TaskQueueBase
|
||||
void PostTask(std::unique_ptr<webrtc::QueuedTask> task) override;
|
||||
@ -483,6 +501,31 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
||||
uint32_t milliseconds) override;
|
||||
void Delete() override;
|
||||
|
||||
// Helper methods to avoid having to do ToQueuedTask() at the calling places.
|
||||
template <class Closure,
|
||||
typename std::enable_if<!std::is_convertible<
|
||||
Closure,
|
||||
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
|
||||
void PostTask(Closure&& closure) {
|
||||
PostTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)));
|
||||
}
|
||||
template <class Closure,
|
||||
typename std::enable_if<!std::is_convertible<
|
||||
Closure,
|
||||
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
|
||||
void PostDelayedTask(Closure&& closure, uint32_t milliseconds) {
|
||||
PostDelayedTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)),
|
||||
milliseconds);
|
||||
}
|
||||
template <class Closure,
|
||||
typename std::enable_if<!std::is_convertible<
|
||||
Closure,
|
||||
std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
|
||||
void PostDelayedHighPrecisionTask(Closure&& closure, uint32_t milliseconds) {
|
||||
PostDelayedHighPrecisionTask(
|
||||
webrtc::ToQueuedTask(std::forward<Closure>(closure)), milliseconds);
|
||||
}
|
||||
|
||||
// ProcessMessages will process I/O and dispatch messages until:
|
||||
// 1) cms milliseconds have elapsed (returns true)
|
||||
// 2) Stop() is called (returns false)
|
||||
|
||||
@ -712,8 +712,8 @@ TEST(ThreadManager, ProcessAllMessageQueuesWithClearedQueue) {
|
||||
};
|
||||
|
||||
// Post messages (both delayed and non delayed) to both threads.
|
||||
t->PostTask(RTC_FROM_HERE, clearer);
|
||||
rtc::Thread::Current()->PostTask(RTC_FROM_HERE, event_signaler);
|
||||
t->PostTask(clearer);
|
||||
rtc::Thread::Current()->PostTask(event_signaler);
|
||||
ThreadManager::ProcessAllMessageQueuesForTesting();
|
||||
}
|
||||
|
||||
@ -923,7 +923,8 @@ TEST(ThreadPostTaskTest, InvokesWithLambda) {
|
||||
background_thread->Start();
|
||||
|
||||
Event event;
|
||||
background_thread->PostTask(RTC_FROM_HERE, [&event] { event.Set(); });
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE,
|
||||
[&event] { event.Set(); });
|
||||
event.Wait(Event::kForever);
|
||||
}
|
||||
|
||||
@ -934,7 +935,7 @@ TEST(ThreadPostTaskTest, InvokesWithCopiedFunctor) {
|
||||
LifeCycleFunctor::Stats stats;
|
||||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
background_thread->PostTask(RTC_FROM_HERE, functor);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(1u, stats.copy_count);
|
||||
@ -948,7 +949,7 @@ TEST(ThreadPostTaskTest, InvokesWithMovedFunctor) {
|
||||
LifeCycleFunctor::Stats stats;
|
||||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
background_thread->PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(0u, stats.copy_count);
|
||||
@ -963,7 +964,7 @@ TEST(ThreadPostTaskTest, InvokesWithReferencedFunctorShouldCopy) {
|
||||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
LifeCycleFunctor& functor_ref = functor;
|
||||
background_thread->PostTask(RTC_FROM_HERE, functor_ref);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor_ref);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(1u, stats.copy_count);
|
||||
@ -978,7 +979,7 @@ TEST(ThreadPostTaskTest, InvokesWithCopiedFunctorDestroyedOnTargetThread) {
|
||||
bool was_invoked_on_background_thread = false;
|
||||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
background_thread->PostTask(RTC_FROM_HERE, functor);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
@ -992,7 +993,7 @@ TEST(ThreadPostTaskTest, InvokesWithMovedFunctorDestroyedOnTargetThread) {
|
||||
bool was_invoked_on_background_thread = false;
|
||||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
background_thread->PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
@ -1008,7 +1009,7 @@ TEST(ThreadPostTaskTest,
|
||||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
DestructionFunctor& functor_ref = functor;
|
||||
background_thread->PostTask(RTC_FROM_HERE, functor_ref);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor_ref);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
@ -1021,7 +1022,7 @@ TEST(ThreadPostTaskTest, InvokesOnBackgroundThread) {
|
||||
Event event;
|
||||
bool was_invoked_on_background_thread = false;
|
||||
Thread* background_thread_ptr = background_thread.get();
|
||||
background_thread->PostTask(
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE,
|
||||
[background_thread_ptr, &was_invoked_on_background_thread, &event] {
|
||||
was_invoked_on_background_thread = background_thread_ptr->IsCurrent();
|
||||
@ -1040,10 +1041,12 @@ TEST(ThreadPostTaskTest, InvokesAsynchronously) {
|
||||
// thread. The second event ensures that the message is processed.
|
||||
Event event_set_by_test_thread;
|
||||
Event event_set_by_background_thread;
|
||||
background_thread->PostTask(RTC_FROM_HERE, [&event_set_by_test_thread,
|
||||
&event_set_by_background_thread] {
|
||||
WaitAndSetEvent(&event_set_by_test_thread, &event_set_by_background_thread);
|
||||
});
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE,
|
||||
[&event_set_by_test_thread, &event_set_by_background_thread] {
|
||||
WaitAndSetEvent(&event_set_by_test_thread,
|
||||
&event_set_by_background_thread);
|
||||
});
|
||||
event_set_by_test_thread.Set();
|
||||
event_set_by_background_thread.Wait(Event::kForever);
|
||||
}
|
||||
@ -1057,11 +1060,11 @@ TEST(ThreadPostTaskTest, InvokesInPostedOrder) {
|
||||
Event third;
|
||||
Event fourth;
|
||||
|
||||
background_thread->PostTask(
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&first, &second] { WaitAndSetEvent(&first, &second); });
|
||||
background_thread->PostTask(
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&second, &third] { WaitAndSetEvent(&second, &third); });
|
||||
background_thread->PostTask(
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&third, &fourth] { WaitAndSetEvent(&third, &fourth); });
|
||||
|
||||
// All tasks have been posted before the first one is unblocked.
|
||||
@ -1078,7 +1081,7 @@ TEST(ThreadPostDelayedTaskTest, InvokesAsynchronously) {
|
||||
// thread. The second event ensures that the message is processed.
|
||||
Event event_set_by_test_thread;
|
||||
Event event_set_by_background_thread;
|
||||
background_thread->PostDelayedTask(
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE,
|
||||
[&event_set_by_test_thread, &event_set_by_background_thread] {
|
||||
WaitAndSetEvent(&event_set_by_test_thread,
|
||||
@ -1099,13 +1102,13 @@ TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) {
|
||||
Event third;
|
||||
Event fourth;
|
||||
|
||||
background_thread->PostDelayedTask(
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&third, &fourth] { WaitAndSetEvent(&third, &fourth); },
|
||||
/*milliseconds=*/11);
|
||||
background_thread->PostDelayedTask(
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&first, &second] { WaitAndSetEvent(&first, &second); },
|
||||
/*milliseconds=*/9);
|
||||
background_thread->PostDelayedTask(
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&second, &third] { WaitAndSetEvent(&second, &third); },
|
||||
/*milliseconds=*/10);
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ void AndroidVideoTrackSource::SetState(JNIEnv* env,
|
||||
} else {
|
||||
// TODO(sakal): Is this even necessary, does FireOnChanged have to be
|
||||
// called from signaling thread?
|
||||
signaling_thread_->PostTask(RTC_FROM_HERE, [this] { FireOnChanged(); });
|
||||
signaling_thread_->PostTask([this] { FireOnChanged(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){
|
||||
rtc::Event waitLock;
|
||||
rtc::Event waitCleanup;
|
||||
constexpr int timeoutMs = 5000;
|
||||
thread->PostTask(RTC_FROM_HERE, [audioSession, &waitLock, &waitCleanup] {
|
||||
thread->PostTask([audioSession, &waitLock, &waitCleanup] {
|
||||
[audioSession lockForConfiguration];
|
||||
waitLock.Set();
|
||||
waitCleanup.Wait(timeoutMs);
|
||||
|
||||
@ -41,7 +41,7 @@ EmulatedNetworkManager::EmulatedNetworkManager(
|
||||
void EmulatedNetworkManager::EnableEndpoint(EmulatedEndpointImpl* endpoint) {
|
||||
RTC_CHECK(endpoints_container_->HasEndpoint(endpoint))
|
||||
<< "No such interface: " << endpoint->GetPeerLocalAddress().ToString();
|
||||
network_thread_->PostTask(RTC_FROM_HERE, [this, endpoint]() {
|
||||
network_thread_->PostTask([this, endpoint]() {
|
||||
endpoint->Enable();
|
||||
UpdateNetworksOnce();
|
||||
});
|
||||
@ -50,7 +50,7 @@ void EmulatedNetworkManager::EnableEndpoint(EmulatedEndpointImpl* endpoint) {
|
||||
void EmulatedNetworkManager::DisableEndpoint(EmulatedEndpointImpl* endpoint) {
|
||||
RTC_CHECK(endpoints_container_->HasEndpoint(endpoint))
|
||||
<< "No such interface: " << endpoint->GetPeerLocalAddress().ToString();
|
||||
network_thread_->PostTask(RTC_FROM_HERE, [this, endpoint]() {
|
||||
network_thread_->PostTask([this, endpoint]() {
|
||||
endpoint->Disable();
|
||||
UpdateNetworksOnce();
|
||||
});
|
||||
@ -66,11 +66,9 @@ void EmulatedNetworkManager::StartUpdating() {
|
||||
// we should trigger network signal immediately for the new clients
|
||||
// to start allocating ports.
|
||||
if (sent_first_update_)
|
||||
network_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this]() { MaybeSignalNetworksChanged(); });
|
||||
network_thread_->PostTask([this]() { MaybeSignalNetworksChanged(); });
|
||||
} else {
|
||||
network_thread_->PostTask(RTC_FROM_HERE,
|
||||
[this]() { UpdateNetworksOnce(); });
|
||||
network_thread_->PostTask([this]() { UpdateNetworksOnce(); });
|
||||
}
|
||||
++start_count_;
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ rtc::AsyncPacketSocket* EmulatedTURNServer::Wrap(EmulatedEndpoint* endpoint) {
|
||||
|
||||
void EmulatedTURNServer::OnPacketReceived(webrtc::EmulatedIpPacket packet) {
|
||||
// Copy from EmulatedEndpoint to rtc::AsyncPacketSocket.
|
||||
thread_->PostTask(RTC_FROM_HERE, [this, packet(std::move(packet))]() {
|
||||
thread_->PostTask([this, packet(std::move(packet))]() {
|
||||
RTC_DCHECK_RUN_ON(thread_.get());
|
||||
auto it = sockets_.find(packet.to);
|
||||
if (it != sockets_.end()) {
|
||||
|
||||
@ -235,10 +235,8 @@ TEST(NetworkEmulationManagerTest, Run) {
|
||||
t2->Invoke<void>(RTC_FROM_HERE, [&] { s2->Connect(a1); });
|
||||
|
||||
for (uint64_t i = 0; i < 1000; i++) {
|
||||
t1->PostTask(RTC_FROM_HERE,
|
||||
[&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask(RTC_FROM_HERE,
|
||||
[&]() { s2->Send(data.data(), data.size()); });
|
||||
t1->PostTask([&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask([&]() { s2->Send(data.data(), data.size()); });
|
||||
}
|
||||
|
||||
network_manager.time_controller()->AdvanceTime(TimeDelta::Seconds(1));
|
||||
@ -391,10 +389,8 @@ TEST(NetworkEmulationManagerTest, DebugStatsCollectedInDebugMode) {
|
||||
t2->Invoke<void>(RTC_FROM_HERE, [&] { s2->Connect(a1); });
|
||||
|
||||
for (uint64_t i = 0; i < 1000; i++) {
|
||||
t1->PostTask(RTC_FROM_HERE,
|
||||
[&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask(RTC_FROM_HERE,
|
||||
[&]() { s2->Send(data.data(), data.size()); });
|
||||
t1->PostTask([&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask([&]() { s2->Send(data.data(), data.size()); });
|
||||
}
|
||||
|
||||
network_manager.time_controller()->AdvanceTime(TimeDelta::Seconds(1));
|
||||
@ -498,8 +494,8 @@ TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
||||
const int kNumPacketsSent = 11;
|
||||
const TimeDelta kDelay = TimeDelta::Millis(100);
|
||||
for (int i = 0; i < kNumPacketsSent; i++) {
|
||||
t1->PostTask(RTC_FROM_HERE, [&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask(RTC_FROM_HERE, [&]() { s2->Send(data.data(), data.size()); });
|
||||
t1->PostTask([&]() { s1->Send(data.data(), data.size()); });
|
||||
t2->PostTask([&]() { s2->Send(data.data(), data.size()); });
|
||||
network_manager.time_controller()->AdvanceTime(kDelay);
|
||||
}
|
||||
|
||||
|
||||
@ -364,9 +364,8 @@ void PeerScenarioClient::SetSdpOfferAndGetAnswer(
|
||||
std::string remote_offer,
|
||||
std::function<void(std::string)> answer_handler) {
|
||||
if (!signaling_thread_->IsCurrent()) {
|
||||
signaling_thread_->PostTask(RTC_FROM_HERE, [=] {
|
||||
SetSdpOfferAndGetAnswer(remote_offer, answer_handler);
|
||||
});
|
||||
signaling_thread_->PostTask(
|
||||
[=] { SetSdpOfferAndGetAnswer(remote_offer, answer_handler); });
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK_RUN_ON(signaling_thread_);
|
||||
@ -397,7 +396,7 @@ void PeerScenarioClient::SetSdpAnswer(
|
||||
std::function<void(const SessionDescriptionInterface&)> done_handler) {
|
||||
if (!signaling_thread_->IsCurrent()) {
|
||||
signaling_thread_->PostTask(
|
||||
RTC_FROM_HERE, [=] { SetSdpAnswer(remote_answer, done_handler); });
|
||||
[=] { SetSdpAnswer(remote_answer, done_handler); });
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK_RUN_ON(signaling_thread_);
|
||||
|
||||
@ -139,26 +139,24 @@ void ScenarioIceConnectionImpl::SendRtpPacket(
|
||||
rtc::ArrayView<const uint8_t> packet_view) {
|
||||
rtc::CopyOnWriteBuffer packet(packet_view.data(), packet_view.size(),
|
||||
::cricket::kMaxRtpPacketLen);
|
||||
network_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
if (rtp_transport_ != nullptr)
|
||||
rtp_transport_->SendRtpPacket(&packet, rtc::PacketOptions(),
|
||||
cricket::PF_SRTP_BYPASS);
|
||||
});
|
||||
network_thread_->PostTask([this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
if (rtp_transport_ != nullptr)
|
||||
rtp_transport_->SendRtpPacket(&packet, rtc::PacketOptions(),
|
||||
cricket::PF_SRTP_BYPASS);
|
||||
});
|
||||
}
|
||||
|
||||
void ScenarioIceConnectionImpl::SendRtcpPacket(
|
||||
rtc::ArrayView<const uint8_t> packet_view) {
|
||||
rtc::CopyOnWriteBuffer packet(packet_view.data(), packet_view.size(),
|
||||
::cricket::kMaxRtpPacketLen);
|
||||
network_thread_->PostTask(
|
||||
RTC_FROM_HERE, [this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
if (rtp_transport_ != nullptr)
|
||||
rtp_transport_->SendRtcpPacket(&packet, rtc::PacketOptions(),
|
||||
cricket::PF_SRTP_BYPASS);
|
||||
});
|
||||
network_thread_->PostTask([this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
if (rtp_transport_ != nullptr)
|
||||
rtp_transport_->SendRtcpPacket(&packet, rtc::PacketOptions(),
|
||||
cricket::PF_SRTP_BYPASS);
|
||||
});
|
||||
}
|
||||
void ScenarioIceConnectionImpl::SetRemoteSdp(SdpType type,
|
||||
const std::string& remote_sdp) {
|
||||
@ -189,7 +187,7 @@ void ScenarioIceConnectionImpl::SetRemoteSdp(SdpType type,
|
||||
}
|
||||
}
|
||||
|
||||
network_thread_->PostTask(RTC_FROM_HERE, [this, criteria]() {
|
||||
network_thread_->PostTask([this, criteria]() {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
RTC_DCHECK(rtp_transport_);
|
||||
rtp_transport_->RegisterRtpDemuxerSink(criteria, this);
|
||||
|
||||
@ -46,9 +46,8 @@ void StartIceSignalingForRoute(PeerScenarioClient* caller,
|
||||
[=](const IceCandidateInterface* candidate) {
|
||||
IceMessage msg(candidate);
|
||||
send_route->NetworkDelayedAction(kIcePacketSize, [callee, msg]() {
|
||||
callee->thread()->PostTask(RTC_FROM_HERE, [callee, msg]() {
|
||||
callee->AddIceCandidate(msg.AsCandidate());
|
||||
});
|
||||
callee->thread()->PostTask(
|
||||
[callee, msg]() { callee->AddIceCandidate(msg.AsCandidate()); });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -50,9 +50,8 @@ void VideoQualityAnalyzer::HandleFramePair(VideoFramePair sample) {
|
||||
psnr = I420PSNR(*sample.captured->ToI420(), *sample.decoded->ToI420());
|
||||
|
||||
if (config_.thread) {
|
||||
config_.thread->PostTask(RTC_FROM_HERE, [this, sample, psnr] {
|
||||
HandleFramePair(std::move(sample), psnr);
|
||||
});
|
||||
config_.thread->PostTask(
|
||||
[this, sample, psnr] { HandleFramePair(std::move(sample), psnr); });
|
||||
} else {
|
||||
HandleFramePair(std::move(sample), psnr);
|
||||
}
|
||||
|
||||
@ -13,13 +13,12 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/task_utils/repeating_task.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
#include "rtc_base/event.h"
|
||||
|
||||
// NOTE: Since these tests rely on real time behavior, they will be flaky
|
||||
// if run on heavily loaded systems.
|
||||
namespace webrtc {
|
||||
@ -134,7 +133,7 @@ TEST(SimulatedTimeControllerTest, ThreadYeildsOnInvoke) {
|
||||
bool task_has_run = false;
|
||||
// Posting a task to the main thread, this should not run until AdvanceTime is
|
||||
// called.
|
||||
main_thread->PostTask(RTC_FROM_HERE, [&] { task_has_run = true; });
|
||||
main_thread->PostTask([&] { task_has_run = true; });
|
||||
t2->Invoke<void>(RTC_FROM_HERE, [] {
|
||||
rtc::Event yield_event;
|
||||
// Wait() triggers YieldExecution() which will runs message processing on
|
||||
|
||||
@ -88,8 +88,8 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostOrderTest) {
|
||||
// Tasks on thread have to be executed in order in which they were
|
||||
// posted.
|
||||
ExecutionOrderKeeper execution_order;
|
||||
thread->PostTask(RTC_FROM_HERE, [&]() { execution_order.Executed(1); });
|
||||
thread->PostTask(RTC_FROM_HERE, [&]() { execution_order.Executed(2); });
|
||||
thread->PostTask([&]() { execution_order.Executed(1); });
|
||||
thread->PostTask([&]() { execution_order.Executed(2); });
|
||||
time_controller->AdvanceTime(TimeDelta::Millis(100));
|
||||
EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2}));
|
||||
// Destroy `thread` before `execution_order` to be sure `execution_order`
|
||||
@ -121,7 +121,7 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostInvokeOrderTest) {
|
||||
// Tasks on thread have to be executed in order in which they were
|
||||
// posted/invoked.
|
||||
ExecutionOrderKeeper execution_order;
|
||||
thread->PostTask(RTC_FROM_HERE, [&]() { execution_order.Executed(1); });
|
||||
thread->PostTask([&]() { execution_order.Executed(1); });
|
||||
thread->Invoke<void>(RTC_FROM_HERE, [&]() { execution_order.Executed(2); });
|
||||
time_controller->AdvanceTime(TimeDelta::Millis(100));
|
||||
EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2}));
|
||||
@ -139,8 +139,8 @@ TEST_P(SimulatedRealTimeControllerConformanceTest,
|
||||
// If task is invoked from thread X on thread X it has to be executed
|
||||
// immediately.
|
||||
ExecutionOrderKeeper execution_order;
|
||||
thread->PostTask(RTC_FROM_HERE, [&]() {
|
||||
thread->PostTask(RTC_FROM_HERE, [&]() { execution_order.Executed(2); });
|
||||
thread->PostTask([&]() {
|
||||
thread->PostTask([&]() { execution_order.Executed(2); });
|
||||
thread->Invoke<void>(RTC_FROM_HERE, [&]() { execution_order.Executed(1); });
|
||||
});
|
||||
time_controller->AdvanceTime(TimeDelta::Millis(100));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user