mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Delete legacy rtc::Thread PostTask APIs.
rtc::Thread already contains PostTask/PostDelayedTask methods that are inherited from webrtc::TaskQueueBase which are named the same thing and do the same thing. Bug: webrtc:13582 Change-Id: I23d897a0079496d89564a51cbb26d214b70e132a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/248168 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35881}
This commit is contained in:
parent
2f122e4fe6
commit
595f688b56
3 changed files with 23 additions and 100 deletions
|
@ -659,7 +659,7 @@ TEST_P(PeerConnectionSignalingTest,
|
|||
// Process all currently pending messages by waiting for a posted task to run.
|
||||
bool checkpoint_reached = false;
|
||||
rtc::Thread::Current()->PostTask(
|
||||
RTC_FROM_HERE, [&checkpoint_reached] { checkpoint_reached = true; });
|
||||
[&checkpoint_reached] { checkpoint_reached = true; });
|
||||
EXPECT_TRUE_WAIT(checkpoint_reached, kWaitTimeout);
|
||||
// If resolving the observer was pending, it must now have been called.
|
||||
EXPECT_TRUE(observer->called());
|
||||
|
|
|
@ -420,79 +420,6 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
|||
// true.
|
||||
bool IsInvokeToThreadAllowed(rtc::Thread* target);
|
||||
|
||||
// Posts a task to invoke the functor on `this` thread asynchronously, i.e.
|
||||
// without blocking the thread that invoked PostTask(). Ownership of `functor`
|
||||
// is passed and (usually, see below) destroyed on `this` thread after it is
|
||||
// invoked.
|
||||
// Requirements of FunctorT:
|
||||
// - FunctorT is movable.
|
||||
// - FunctorT implements "T operator()()" or "T operator()() const" for some T
|
||||
// (if T is not void, the return value is discarded on `this` thread).
|
||||
// - FunctorT has a public destructor that can be invoked from `this` thread
|
||||
// after operation() has been invoked.
|
||||
// - The functor must not cause the thread to quit before PostTask() is done.
|
||||
//
|
||||
// Destruction of the functor/task mimics what TaskQueue::PostTask does: If
|
||||
// the task is run, it will be destroyed on `this` thread. However, if there
|
||||
// are pending tasks by the time the Thread is destroyed, or a task is posted
|
||||
// to a thread that is quitting, the task is destroyed immediately, on the
|
||||
// calling thread. Destroying the Thread only blocks for any currently running
|
||||
// task to complete. Note that TQ abstraction is even vaguer on how
|
||||
// destruction happens in these cases, allowing destruction to happen
|
||||
// asynchronously at a later time and on some arbitrary thread. So to ease
|
||||
// migration, don't depend on Thread::PostTask destroying un-run tasks
|
||||
// immediately.
|
||||
//
|
||||
// Example - Calling a class method:
|
||||
// class Foo {
|
||||
// public:
|
||||
// void DoTheThing();
|
||||
// };
|
||||
// Foo foo;
|
||||
// thread->PostTask(RTC_FROM_HERE, Bind(&Foo::DoTheThing, &foo));
|
||||
//
|
||||
// Example - Calling a lambda function:
|
||||
// thread->PostTask(RTC_FROM_HERE,
|
||||
// [&x, &y] { x.TrackComputations(y.Compute()); });
|
||||
//
|
||||
// TODO(https://crbug.com/webrtc/13582): Deprecate and remove in favor of the
|
||||
// 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 DEPRECATED_PostTask(const Location& posted_from, FunctorT&& functor) {
|
||||
Post(posted_from, GetPostTaskMessageHandler(), /*id=*/0,
|
||||
new rtc_thread_internal::MessageWithFunctor<FunctorT>(
|
||||
std::forward<FunctorT>(functor)));
|
||||
}
|
||||
template <class FunctorT>
|
||||
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;
|
||||
void PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task,
|
||||
|
|
|
@ -923,8 +923,7 @@ TEST(ThreadPostTaskTest, InvokesWithLambda) {
|
|||
background_thread->Start();
|
||||
|
||||
Event event;
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE,
|
||||
[&event] { event.Set(); });
|
||||
background_thread->PostTask([&event] { event.Set(); });
|
||||
event.Wait(Event::kForever);
|
||||
}
|
||||
|
||||
|
@ -935,7 +934,7 @@ TEST(ThreadPostTaskTest, InvokesWithCopiedFunctor) {
|
|||
LifeCycleFunctor::Stats stats;
|
||||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor);
|
||||
background_thread->PostTask(functor);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(1u, stats.copy_count);
|
||||
|
@ -949,7 +948,7 @@ TEST(ThreadPostTaskTest, InvokesWithMovedFunctor) {
|
|||
LifeCycleFunctor::Stats stats;
|
||||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
background_thread->PostTask(std::move(functor));
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(0u, stats.copy_count);
|
||||
|
@ -964,7 +963,7 @@ TEST(ThreadPostTaskTest, InvokesWithReferencedFunctorShouldCopy) {
|
|||
Event event;
|
||||
LifeCycleFunctor functor(&stats, &event);
|
||||
LifeCycleFunctor& functor_ref = functor;
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor_ref);
|
||||
background_thread->PostTask(functor_ref);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_EQ(1u, stats.copy_count);
|
||||
|
@ -979,7 +978,7 @@ TEST(ThreadPostTaskTest, InvokesWithCopiedFunctorDestroyedOnTargetThread) {
|
|||
bool was_invoked_on_background_thread = false;
|
||||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor);
|
||||
background_thread->PostTask(functor);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
|
@ -993,7 +992,7 @@ TEST(ThreadPostTaskTest, InvokesWithMovedFunctorDestroyedOnTargetThread) {
|
|||
bool was_invoked_on_background_thread = false;
|
||||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, std::move(functor));
|
||||
background_thread->PostTask(std::move(functor));
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
|
@ -1009,7 +1008,7 @@ TEST(ThreadPostTaskTest,
|
|||
DestructionFunctor functor(background_thread.get(),
|
||||
&was_invoked_on_background_thread, &event);
|
||||
DestructionFunctor& functor_ref = functor;
|
||||
background_thread->DEPRECATED_PostTask(RTC_FROM_HERE, functor_ref);
|
||||
background_thread->PostTask(functor_ref);
|
||||
event.Wait(Event::kForever);
|
||||
|
||||
EXPECT_TRUE(was_invoked_on_background_thread);
|
||||
|
@ -1022,8 +1021,7 @@ TEST(ThreadPostTaskTest, InvokesOnBackgroundThread) {
|
|||
Event event;
|
||||
bool was_invoked_on_background_thread = false;
|
||||
Thread* background_thread_ptr = background_thread.get();
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE,
|
||||
background_thread->PostTask(
|
||||
[background_thread_ptr, &was_invoked_on_background_thread, &event] {
|
||||
was_invoked_on_background_thread = background_thread_ptr->IsCurrent();
|
||||
event.Set();
|
||||
|
@ -1041,8 +1039,7 @@ 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->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE,
|
||||
background_thread->PostTask(
|
||||
[&event_set_by_test_thread, &event_set_by_background_thread] {
|
||||
WaitAndSetEvent(&event_set_by_test_thread,
|
||||
&event_set_by_background_thread);
|
||||
|
@ -1060,12 +1057,12 @@ TEST(ThreadPostTaskTest, InvokesInPostedOrder) {
|
|||
Event third;
|
||||
Event fourth;
|
||||
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&first, &second] { WaitAndSetEvent(&first, &second); });
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&second, &third] { WaitAndSetEvent(&second, &third); });
|
||||
background_thread->DEPRECATED_PostTask(
|
||||
RTC_FROM_HERE, [&third, &fourth] { WaitAndSetEvent(&third, &fourth); });
|
||||
background_thread->PostTask(
|
||||
[&first, &second] { WaitAndSetEvent(&first, &second); });
|
||||
background_thread->PostTask(
|
||||
[&second, &third] { WaitAndSetEvent(&second, &third); });
|
||||
background_thread->PostTask(
|
||||
[&third, &fourth] { WaitAndSetEvent(&third, &fourth); });
|
||||
|
||||
// All tasks have been posted before the first one is unblocked.
|
||||
first.Set();
|
||||
|
@ -1081,8 +1078,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->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE,
|
||||
background_thread->PostDelayedTask(
|
||||
[&event_set_by_test_thread, &event_set_by_background_thread] {
|
||||
WaitAndSetEvent(&event_set_by_test_thread,
|
||||
&event_set_by_background_thread);
|
||||
|
@ -1102,14 +1098,14 @@ TEST(ThreadPostDelayedTaskTest, InvokesInDelayOrder) {
|
|||
Event third;
|
||||
Event fourth;
|
||||
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&third, &fourth] { WaitAndSetEvent(&third, &fourth); },
|
||||
background_thread->PostDelayedTask(
|
||||
[&third, &fourth] { WaitAndSetEvent(&third, &fourth); },
|
||||
/*milliseconds=*/11);
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&first, &second] { WaitAndSetEvent(&first, &second); },
|
||||
background_thread->PostDelayedTask(
|
||||
[&first, &second] { WaitAndSetEvent(&first, &second); },
|
||||
/*milliseconds=*/9);
|
||||
background_thread->DEPRECATED_PostDelayedTask(
|
||||
RTC_FROM_HERE, [&second, &third] { WaitAndSetEvent(&second, &third); },
|
||||
background_thread->PostDelayedTask(
|
||||
[&second, &third] { WaitAndSetEvent(&second, &third); },
|
||||
/*milliseconds=*/10);
|
||||
|
||||
// All tasks have been posted before the first one is unblocked.
|
||||
|
|
Loading…
Reference in a new issue