Migrate rtc_base and rtc_tools to absl::AnyInvocable based TaskQueueBase interface
Bug: webrtc:14245
Change-Id: I71abe3db7a23ad33bd175297e23fa8e927fa9628
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/268768
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37553}
diff --git a/rtc_base/task_queue_for_test.h b/rtc_base/task_queue_for_test.h
index c1de874..450050a 100644
--- a/rtc_base/task_queue_for_test.h
+++ b/rtc_base/task_queue_for_test.h
@@ -13,9 +13,10 @@
#include <utility>
+#include "absl/cleanup/cleanup.h"
#include "absl/strings/string_view.h"
+#include "api/function_view.h"
#include "api/task_queue/task_queue_base.h"
-#include "api/task_queue/to_queued_task.h"
#include "rtc_base/checks.h"
#include "rtc_base/event.h"
#include "rtc_base/location.h"
@@ -24,13 +25,14 @@
namespace webrtc {
-template <typename Closure>
-void SendTask(rtc::Location loc, TaskQueueBase* task_queue, Closure&& task) {
+inline void SendTask(rtc::Location loc,
+ TaskQueueBase* task_queue,
+ rtc::FunctionView<void()> task) {
RTC_CHECK(!task_queue->IsCurrent())
<< "Called SendTask to a queue from the same queue at " << loc.ToString();
rtc::Event event;
- task_queue->PostTask(
- ToQueuedTask(std::forward<Closure>(task), [&event] { event.Set(); }));
+ absl::Cleanup cleanup = [&event] { event.Set(); };
+ task_queue->PostTask([task, cleanup = std::move(cleanup)] { task(); });
RTC_CHECK(event.Wait(/*give_up_after_ms=*/rtc::Event::kForever,
/*warn_after_ms=*/10'000))
<< "Waited too long at " << loc.ToString();
@@ -47,24 +49,8 @@
// A convenience, test-only method that blocks the current thread while
// a task executes on the task queue.
- // This variant is specifically for posting custom QueuedTask derived
- // implementations that tests do not want to pass ownership of over to the
- // task queue (i.e. the Run() method always returns `false`.).
- template <class Closure>
- void SendTask(Closure* task) {
- RTC_CHECK(!IsCurrent());
- rtc::Event event;
- PostTask(ToQueuedTask(
- [&task] { RTC_CHECK_EQ(false, static_cast<QueuedTask*>(task)->Run()); },
- [&event] { event.Set(); }));
- event.Wait(rtc::Event::kForever);
- }
-
- // A convenience, test-only method that blocks the current thread while
- // a task executes on the task queue.
- template <class Closure>
- void SendTask(Closure&& task, rtc::Location loc) {
- ::webrtc::SendTask(loc, Get(), std::forward<Closure>(task));
+ void SendTask(rtc::FunctionView<void()> task, rtc::Location loc) {
+ ::webrtc::SendTask(loc, Get(), task);
}
// Wait for the completion of all tasks posted prior to the