diff --git a/pc/peer_connection_signaling_unittest.cc b/pc/peer_connection_signaling_unittest.cc index 48a99883c0..90dd868de6 100644 --- a/pc/peer_connection_signaling_unittest.cc +++ b/pc/peer_connection_signaling_unittest.cc @@ -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()); diff --git a/rtc_base/thread.h b/rtc_base/thread.h index f8174e3d39..bc93e6533c 100644 --- a/rtc_base/thread.h +++ b/rtc_base/thread.h @@ -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 - void DEPRECATED_PostTask(const Location& posted_from, FunctorT&& functor) { - Post(posted_from, GetPostTaskMessageHandler(), /*id=*/0, - new rtc_thread_internal::MessageWithFunctor( - std::forward(functor))); - } - template - ABSL_DEPRECATED("bugs.webrtc.org/13582") - void PostTask(const Location& posted_from, FunctorT&& functor) { - DEPRECATED_PostTask(posted_from, std::forward(functor)); - } - template - void DEPRECATED_PostDelayedTask(const Location& posted_from, - FunctorT&& functor, - uint32_t milliseconds) { - PostDelayed(posted_from, milliseconds, GetPostTaskMessageHandler(), - /*id=*/0, - new rtc_thread_internal::MessageWithFunctor( - std::forward(functor))); - } - template - ABSL_DEPRECATED("bugs.webrtc.org/13582") - void PostDelayedTask(const Location& posted_from, - FunctorT&& functor, - uint32_t milliseconds) { - DEPRECATED_PostDelayedTask(posted_from, std::forward(functor), - milliseconds); - } - // From TaskQueueBase void PostTask(std::unique_ptr task) override; void PostDelayedTask(std::unique_ptr task, diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc index 10859e2225..53b23ad904 100644 --- a/rtc_base/thread_unittest.cc +++ b/rtc_base/thread_unittest.cc @@ -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.