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 <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33905}
This commit is contained in:
Niels Möller
2021-05-03 16:03:22 +02:00
committed by WebRTC LUCI CQ
parent de88b08b94
commit 0694ce7d1b
5 changed files with 39 additions and 32 deletions

View File

@ -125,7 +125,7 @@ class DEPRECATED_NackModule : public Module {
const absl::optional<BackoffSettings> backoff_settings_;
};
using NackModule = ABSL_DEPRECATED("") DEPRECATED_NackModule;
using NackModule ABSL_DEPRECATED("") = DEPRECATED_NackModule;
} // namespace webrtc

View File

@ -15,12 +15,12 @@
namespace rtc {
AsyncInvoker::AsyncInvoker()
DEPRECATED_AsyncInvoker::DEPRECATED_AsyncInvoker()
: pending_invocations_(0),
invocation_complete_(make_ref_counted<Event>()),
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<AsyncClosure>* data =
static_cast<ScopedMessageData<AsyncClosure>*>(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<AsyncClosure> closure,
uint32_t id) {
void DEPRECATED_AsyncInvoker::DoInvoke(const Location& posted_from,
Thread* thread,
std::unique_ptr<AsyncClosure> 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<AsyncClosure>(std::move(closure)));
}
void AsyncInvoker::DoInvokeDelayed(const Location& posted_from,
Thread* thread,
std::unique_ptr<AsyncClosure> closure,
uint32_t delay_ms,
uint32_t id) {
void DEPRECATED_AsyncInvoker::DoInvokeDelayed(
const Location& posted_from,
Thread* thread,
std::unique_ptr<AsyncClosure> 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<AsyncClosure>(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);
}

View File

@ -15,6 +15,7 @@
#include <memory>
#include <utility>
#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_

View File

@ -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 FunctorT>
class FireAndForgetAsyncClosure : public AsyncClosure {
public:
explicit FireAndForgetAsyncClosure(AsyncInvoker* invoker, FunctorT&& functor)
explicit FireAndForgetAsyncClosure(DEPRECATED_AsyncInvoker* invoker,
FunctorT&& functor)
: AsyncClosure(invoker), functor_(std::forward<FunctorT>(functor)) {}
virtual void Execute() { functor_(); }

View File

@ -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<void>(RTC_FROM_HERE, thread.get(), functor);
functor_started.Wait(Event::kForever);
@ -833,7 +833,7 @@ TEST_F(AsyncInvokeTest, KillInvokerDuringExecuteWithReentrantInvoke) {
Thread thread(std::make_unique<NullSocketServer>());
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.