Delete rtc::Thread::Send in favor of rtc::Thread::BlockingCall
Bug: webrtc:9702
Change-Id: Ie425c99e8d05ad84801b527207732e4d45494dbd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275242
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38071}
diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc
index 9c36749..da0ea4b 100644
--- a/rtc_base/thread.cc
+++ b/rtc_base/thread.cc
@@ -851,29 +851,20 @@
Join();
}
-void Thread::Send(const Location& posted_from,
- MessageHandler* phandler,
- uint32_t id,
- MessageData* pdata) {
+void Thread::BlockingCall(rtc::FunctionView<void()> functor) {
+ TRACE_EVENT0("webrtc", "Thread::BlockingCall");
+
RTC_DCHECK(!IsQuitting());
if (IsQuitting())
return;
- // Sent messages are sent to the MessageHandler directly, in the context
- // of "thread", like Win32 SendMessage. If in the right context,
- // call the handler directly.
- Message msg;
- msg.posted_from = posted_from;
- msg.phandler = phandler;
- msg.message_id = id;
- msg.pdata = pdata;
if (IsCurrent()) {
#if RTC_DCHECK_IS_ON
RTC_DCHECK(this->IsInvokeToThreadAllowed(this));
RTC_DCHECK_RUN_ON(this);
could_be_blocking_call_count_++;
#endif
- msg.phandler->OnMessage(&msg);
+ functor();
return;
}
@@ -892,7 +883,7 @@
#endif
// Perhaps down the line we can get rid of this workaround and always require
- // current_thread to be valid when Send() is called.
+ // current_thread to be valid when BlockingCall() is called.
std::unique_ptr<rtc::Event> done_event;
if (!current_thread)
done_event.reset(new rtc::Event());
@@ -908,9 +899,7 @@
done->Set();
}
};
- PostTask([&msg, cleanup = std::move(cleanup)]() mutable {
- msg.phandler->OnMessage(&msg);
- });
+ PostTask([functor, cleanup = std::move(cleanup)] { functor(); });
if (current_thread) {
bool waited = false;
crit_.Enter();
@@ -941,22 +930,6 @@
}
}
-void Thread::BlockingCall(rtc::FunctionView<void()> functor) {
- TRACE_EVENT0("webrtc", "Thread::BlockingCall");
-
- class FunctorMessageHandler : public MessageHandler {
- public:
- explicit FunctorMessageHandler(rtc::FunctionView<void()> functor)
- : functor_(functor) {}
- void OnMessage(Message* msg) override { functor_(); }
-
- private:
- rtc::FunctionView<void()> functor_;
- } handler(functor);
-
- Send(/*posted_from=*/{}, &handler, /*id=*/0, /*pdata=*/nullptr);
-}
-
// Called by the ThreadManager when being set as the current thread.
void Thread::EnsureIsCurrentTaskQueue() {
task_queue_registration_ =
diff --git a/rtc_base/thread.h b/rtc_base/thread.h
index 435aff6..65b9361 100644
--- a/rtc_base/thread.h
+++ b/rtc_base/thread.h
@@ -498,13 +498,6 @@
private:
static const int kSlowDispatchLoggingThreshold = 50; // 50 ms
- // TODO(bugs.webrtc.org/9702): Delete and move Send's implementation into
- // `BlockingCall` when derived classes override `BlockingCall` instead.
- virtual void Send(const Location& posted_from,
- MessageHandler* phandler,
- uint32_t id,
- MessageData* pdata);
-
// Get() will process I/O until:
// 1) A message is available (returns true)
// 2) cmsWait seconds have elapsed (returns false)