diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc index 9c3674980b..da0ea4b318 100644 --- a/rtc_base/thread.cc +++ b/rtc_base/thread.cc @@ -851,29 +851,20 @@ void Thread::Stop() { Join(); } -void Thread::Send(const Location& posted_from, - MessageHandler* phandler, - uint32_t id, - MessageData* pdata) { +void Thread::BlockingCall(rtc::FunctionView 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 @@ void Thread::Send(const Location& posted_from, #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 done_event; if (!current_thread) done_event.reset(new rtc::Event()); @@ -908,9 +899,7 @@ void Thread::Send(const Location& posted_from, 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::Send(const Location& posted_from, } } -void Thread::BlockingCall(rtc::FunctionView functor) { - TRACE_EVENT0("webrtc", "Thread::BlockingCall"); - - class FunctorMessageHandler : public MessageHandler { - public: - explicit FunctorMessageHandler(rtc::FunctionView functor) - : functor_(functor) {} - void OnMessage(Message* msg) override { functor_(); } - - private: - rtc::FunctionView 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 435aff6d94..65b9361871 100644 --- a/rtc_base/thread.h +++ b/rtc_base/thread.h @@ -498,13 +498,6 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase { 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)