From 0694ce7d1b858ffba5c8cf1067eb0882b36d69cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 3 May 2021 16:03:22 +0200 Subject: [PATCH] Mark AsyncInvoker as deprecated Also fix similar annotation on NackModule to have effect (when defining an alias with C++ using, ABSL_DEPRECATED should appear on the left hand side). Bug: webrtc:12339 Change-Id: Id80a20bf2c56a826777b8a40e06ac5c65e4f8db7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/217242 Reviewed-by: Harald Alvestrand Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#33905} --- modules/video_coding/deprecated/nack_module.h | 2 +- rtc_base/async_invoker.cc | 32 ++++++++++--------- rtc_base/async_invoker.h | 12 ++++--- rtc_base/async_invoker_inl.h | 9 +++--- rtc_base/thread_unittest.cc | 16 +++++----- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/modules/video_coding/deprecated/nack_module.h b/modules/video_coding/deprecated/nack_module.h index 0ad009b597..2fac6ce128 100644 --- a/modules/video_coding/deprecated/nack_module.h +++ b/modules/video_coding/deprecated/nack_module.h @@ -125,7 +125,7 @@ class DEPRECATED_NackModule : public Module { const absl::optional backoff_settings_; }; -using NackModule = ABSL_DEPRECATED("") DEPRECATED_NackModule; +using NackModule ABSL_DEPRECATED("") = DEPRECATED_NackModule; } // namespace webrtc diff --git a/rtc_base/async_invoker.cc b/rtc_base/async_invoker.cc index f758670c07..87d039373d 100644 --- a/rtc_base/async_invoker.cc +++ b/rtc_base/async_invoker.cc @@ -15,12 +15,12 @@ namespace rtc { -AsyncInvoker::AsyncInvoker() +DEPRECATED_AsyncInvoker::DEPRECATED_AsyncInvoker() : pending_invocations_(0), invocation_complete_(make_ref_counted()), destroying_(false) {} -AsyncInvoker::~AsyncInvoker() { +DEPRECATED_AsyncInvoker::~DEPRECATED_AsyncInvoker() { destroying_.store(true, std::memory_order_relaxed); // Messages for this need to be cleared *before* our destructor is complete. ThreadManager::Clear(this); @@ -37,7 +37,7 @@ AsyncInvoker::~AsyncInvoker() { } } -void AsyncInvoker::OnMessage(Message* msg) { +void DEPRECATED_AsyncInvoker::OnMessage(Message* msg) { // Get the AsyncClosure shared ptr from this message's data. ScopedMessageData* data = static_cast*>(msg->pdata); @@ -46,7 +46,8 @@ void AsyncInvoker::OnMessage(Message* msg) { delete data; } -void AsyncInvoker::Flush(Thread* thread, uint32_t id /*= MQID_ANY*/) { +void DEPRECATED_AsyncInvoker::Flush(Thread* thread, + uint32_t id /*= MQID_ANY*/) { // If the destructor is waiting for invocations to finish, don't start // running even more tasks. if (destroying_.load(std::memory_order_relaxed)) @@ -67,14 +68,14 @@ void AsyncInvoker::Flush(Thread* thread, uint32_t id /*= MQID_ANY*/) { } } -void AsyncInvoker::Clear() { +void DEPRECATED_AsyncInvoker::Clear() { ThreadManager::Clear(this); } -void AsyncInvoker::DoInvoke(const Location& posted_from, - Thread* thread, - std::unique_ptr closure, - uint32_t id) { +void DEPRECATED_AsyncInvoker::DoInvoke(const Location& posted_from, + Thread* thread, + std::unique_ptr closure, + uint32_t id) { if (destroying_.load(std::memory_order_relaxed)) { // Note that this may be expected, if the application is AsyncInvoking // tasks that AsyncInvoke other tasks. But otherwise it indicates a race @@ -87,11 +88,12 @@ void AsyncInvoker::DoInvoke(const Location& posted_from, new ScopedMessageData(std::move(closure))); } -void AsyncInvoker::DoInvokeDelayed(const Location& posted_from, - Thread* thread, - std::unique_ptr closure, - uint32_t delay_ms, - uint32_t id) { +void DEPRECATED_AsyncInvoker::DoInvokeDelayed( + const Location& posted_from, + Thread* thread, + std::unique_ptr closure, + uint32_t delay_ms, + uint32_t id) { if (destroying_.load(std::memory_order_relaxed)) { // See above comment. RTC_LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; @@ -101,7 +103,7 @@ void AsyncInvoker::DoInvokeDelayed(const Location& posted_from, new ScopedMessageData(std::move(closure))); } -AsyncClosure::AsyncClosure(AsyncInvoker* invoker) +AsyncClosure::AsyncClosure(DEPRECATED_AsyncInvoker* invoker) : invoker_(invoker), invocation_complete_(invoker_->invocation_complete_) { invoker_->pending_invocations_.fetch_add(1, std::memory_order_relaxed); } diff --git a/rtc_base/async_invoker.h b/rtc_base/async_invoker.h index 01ab19e998..fd42ca76de 100644 --- a/rtc_base/async_invoker.h +++ b/rtc_base/async_invoker.h @@ -15,6 +15,7 @@ #include #include +#include "absl/base/attributes.h" #include "api/scoped_refptr.h" #include "rtc_base/async_invoker_inl.h" #include "rtc_base/constructor_magic.h" @@ -86,10 +87,10 @@ namespace rtc { // destruction. This can be done by starting each chain of invocations on the // same thread on which it will be destroyed, or by using some other // synchronization method. -class AsyncInvoker : public MessageHandlerAutoCleanup { +class DEPRECATED_AsyncInvoker : public MessageHandlerAutoCleanup { public: - AsyncInvoker(); - ~AsyncInvoker() override; + DEPRECATED_AsyncInvoker(); + ~DEPRECATED_AsyncInvoker() override; // Call |functor| asynchronously on |thread|, with no callback upon // completion. Returns immediately. @@ -165,9 +166,12 @@ class AsyncInvoker : public MessageHandlerAutoCleanup { friend class AsyncClosure; - RTC_DISALLOW_COPY_AND_ASSIGN(AsyncInvoker); + RTC_DISALLOW_COPY_AND_ASSIGN(DEPRECATED_AsyncInvoker); }; +using AsyncInvoker ABSL_DEPRECATED("bugs.webrtc.org/12339") = + DEPRECATED_AsyncInvoker; + } // namespace rtc #endif // RTC_BASE_ASYNC_INVOKER_H_ diff --git a/rtc_base/async_invoker_inl.h b/rtc_base/async_invoker_inl.h index d731f992b2..9fb328782c 100644 --- a/rtc_base/async_invoker_inl.h +++ b/rtc_base/async_invoker_inl.h @@ -21,20 +21,20 @@ namespace rtc { -class AsyncInvoker; +class DEPRECATED_AsyncInvoker; // Helper class for AsyncInvoker. Runs a task and triggers a callback // on the calling thread if necessary. class AsyncClosure { public: - explicit AsyncClosure(AsyncInvoker* invoker); + explicit AsyncClosure(DEPRECATED_AsyncInvoker* invoker); virtual ~AsyncClosure(); // Runs the asynchronous task, and triggers a callback to the calling // thread if needed. Should be called from the target thread. virtual void Execute() = 0; protected: - AsyncInvoker* invoker_; + DEPRECATED_AsyncInvoker* invoker_; // Reference counted so that if the AsyncInvoker destructor finishes before // an AsyncClosure's destructor that's about to call // "invocation_complete_->Set()", it's not dereferenced after being @@ -46,7 +46,8 @@ class AsyncClosure { template class FireAndForgetAsyncClosure : public AsyncClosure { public: - explicit FireAndForgetAsyncClosure(AsyncInvoker* invoker, FunctorT&& functor) + explicit FireAndForgetAsyncClosure(DEPRECATED_AsyncInvoker* invoker, + FunctorT&& functor) : AsyncClosure(invoker), functor_(std::forward(functor)) {} virtual void Execute() { functor_(); } diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc index 1883c6d839..789bdd943e 100644 --- a/rtc_base/thread_unittest.cc +++ b/rtc_base/thread_unittest.cc @@ -521,7 +521,7 @@ TEST(ThreadTest, ThreeThreadsInvoke) { // Asynchronously invoke SetAndInvokeSet on |thread1| and wait until // |thread1| starts the call. - static void AsyncInvokeSetAndWait(AsyncInvoker* invoker, + static void AsyncInvokeSetAndWait(DEPRECATED_AsyncInvoker* invoker, Thread* thread1, Thread* thread2, LockedBool* out) { @@ -536,7 +536,7 @@ TEST(ThreadTest, ThreeThreadsInvoke) { } }; - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; LockedBool thread_a_called(false); // Start the sequence A --(invoke)--> B --(async invoke)--> C --(invoke)--> A. @@ -761,7 +761,7 @@ class AsyncInvokeTest : public ::testing::Test { }; TEST_F(AsyncInvokeTest, FireAndForget) { - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; // Create and start the thread. auto thread = Thread::CreateWithSocketServer(); thread->Start(); @@ -773,7 +773,7 @@ TEST_F(AsyncInvokeTest, FireAndForget) { } TEST_F(AsyncInvokeTest, NonCopyableFunctor) { - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; // Create and start the thread. auto thread = Thread::CreateWithSocketServer(); thread->Start(); @@ -804,7 +804,7 @@ TEST_F(AsyncInvokeTest, KillInvokerDuringExecute) { EXPECT_FALSE(invoker_destroyed); functor_finished.Set(); }; - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; invoker.AsyncInvoke(RTC_FROM_HERE, thread.get(), functor); functor_started.Wait(Event::kForever); @@ -833,7 +833,7 @@ TEST_F(AsyncInvokeTest, KillInvokerDuringExecuteWithReentrantInvoke) { Thread thread(std::make_unique()); thread.Start(); { - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; auto reentrant_functor = [&reentrant_functor_run] { reentrant_functor_run = true; }; @@ -852,7 +852,7 @@ TEST_F(AsyncInvokeTest, KillInvokerDuringExecuteWithReentrantInvoke) { } TEST_F(AsyncInvokeTest, Flush) { - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; AtomicBool flag1; AtomicBool flag2; // Queue two async calls to the current thread. @@ -868,7 +868,7 @@ TEST_F(AsyncInvokeTest, Flush) { } TEST_F(AsyncInvokeTest, FlushWithIds) { - AsyncInvoker invoker; + DEPRECATED_AsyncInvoker invoker; AtomicBool flag1; AtomicBool flag2; // Queue two async calls to the current thread, one with a message id.