Publish rtc::QueuedTask in api as webrtc::QueuedTask
Bug: webrtc:10191
Change-Id: I7dcba28615c2f3e44442be410dedde15f5fb1deb
Reviewed-on: https://webrtc-review.googlesource.com/c/113502
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26244}
diff --git a/api/task_queue/BUILD.gn b/api/task_queue/BUILD.gn
new file mode 100644
index 0000000..e9dfe66
--- /dev/null
+++ b/api/task_queue/BUILD.gn
@@ -0,0 +1,16 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../webrtc.gni")
+
+rtc_source_set("task_queue") {
+ visibility = [ "*" ]
+ public = [
+ "queued_task.h",
+ ]
+}
diff --git a/api/task_queue/queued_task.h b/api/task_queue/queued_task.h
new file mode 100644
index 0000000..5748628
--- /dev/null
+++ b/api/task_queue/queued_task.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef API_TASK_QUEUE_QUEUED_TASK_H_
+#define API_TASK_QUEUE_QUEUED_TASK_H_
+
+namespace webrtc {
+
+// Base interface for asynchronously executed tasks.
+// The interface basically consists of a single function, Run(), that executes
+// on the target queue. For more details see the Run() method and TaskQueue.
+class QueuedTask {
+ public:
+ virtual ~QueuedTask() = default;
+
+ // Main routine that will run when the task is executed on the desired queue.
+ // The task should return |true| to indicate that it should be deleted or
+ // |false| to indicate that the queue should consider ownership of the task
+ // having been transferred. Returning |false| can be useful if a task has
+ // re-posted itself to a different queue or is otherwise being re-used.
+ virtual bool Run() = 0;
+};
+
+} // namespace webrtc
+
+#endif // API_TASK_QUEUE_QUEUED_TASK_H_
diff --git a/modules/utility/BUILD.gn b/modules/utility/BUILD.gn
index 1d780b0..4354f0c 100644
--- a/modules/utility/BUILD.gn
+++ b/modules/utility/BUILD.gn
@@ -26,10 +26,10 @@
deps = [
"..:module_api",
+ "../../api/task_queue",
"../../common_audio",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
- "../../rtc_base:rtc_task_queue",
"../../rtc_base/system:arch",
"../../system_wrappers",
]
diff --git a/modules/utility/include/mock/mock_process_thread.h b/modules/utility/include/mock/mock_process_thread.h
index fb88e40..6826f52 100644
--- a/modules/utility/include/mock/mock_process_thread.h
+++ b/modules/utility/include/mock/mock_process_thread.h
@@ -28,14 +28,14 @@
MOCK_METHOD0(Start, void());
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(WakeUp, void(Module* module));
- MOCK_METHOD1(PostTask, void(rtc::QueuedTask* task));
+ MOCK_METHOD1(PostTask, void(QueuedTask* task));
MOCK_METHOD2(RegisterModule, void(Module* module, const rtc::Location&));
MOCK_METHOD1(DeRegisterModule, void(Module* module));
// MOCK_METHOD1 gets confused with mocking this method, so we work around it
// by overriding the method from the interface and forwarding the call to a
// mocked, simpler method.
- void PostTask(std::unique_ptr<rtc::QueuedTask> task) /*override*/ {
+ void PostTask(std::unique_ptr<QueuedTask> task) /*override*/ {
PostTask(task.get());
}
};
diff --git a/modules/utility/include/process_thread.h b/modules/utility/include/process_thread.h
index 8c69196..9b02a7ea 100644
--- a/modules/utility/include/process_thread.h
+++ b/modules/utility/include/process_thread.h
@@ -13,15 +13,7 @@
#include <memory>
-#if defined(WEBRTC_WIN)
-// Due to a bug in the std::unique_ptr implementation that ships with MSVS,
-// we need the full definition of QueuedTask, on Windows.
-#include "rtc_base/task_queue.h"
-#else
-namespace rtc {
-class QueuedTask;
-}
-#endif
+#include "api/task_queue/queued_task.h"
namespace rtc {
class Location;
@@ -59,7 +51,7 @@
// construction thread of the ProcessThread instance, if the task did not
// get a chance to run (e.g. posting the task while shutting down or when
// the thread never runs).
- virtual void PostTask(std::unique_ptr<rtc::QueuedTask> task) = 0;
+ virtual void PostTask(std::unique_ptr<QueuedTask> task) = 0;
// Adds a module that will start to receive callbacks on the worker thread.
// Can be called from any thread.
diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc
index fbe60bb..5c2f0ab 100644
--- a/modules/utility/source/process_thread_impl.cc
+++ b/modules/utility/source/process_thread_impl.cc
@@ -14,7 +14,6 @@
#include "modules/include/module.h"
#include "rtc_base/checks.h"
-#include "rtc_base/task_queue.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
@@ -105,7 +104,7 @@
wake_up_.Set();
}
-void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) {
+void ProcessThreadImpl::PostTask(std::unique_ptr<QueuedTask> task) {
// Allowed to be called on any thread.
{
rtc::CritScope lock(&lock_);
@@ -204,7 +203,7 @@
}
while (!queue_.empty()) {
- rtc::QueuedTask* task = queue_.front();
+ QueuedTask* task = queue_.front();
queue_.pop();
lock_.Leave();
task->Run();
diff --git a/modules/utility/source/process_thread_impl.h b/modules/utility/source/process_thread_impl.h
index e927c1d..7339fe1 100644
--- a/modules/utility/source/process_thread_impl.h
+++ b/modules/utility/source/process_thread_impl.h
@@ -16,13 +16,13 @@
#include <memory>
#include <queue>
+#include "api/task_queue/queued_task.h"
#include "modules/include/module.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/location.h"
#include "rtc_base/platform_thread.h"
-#include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h"
namespace webrtc {
@@ -36,7 +36,7 @@
void Stop() override;
void WakeUp(Module* module) override;
- void PostTask(std::unique_ptr<rtc::QueuedTask> task) override;
+ void PostTask(std::unique_ptr<QueuedTask> task) override;
void RegisterModule(Module* module, const rtc::Location& from) override;
void DeRegisterModule(Module* module) override;
@@ -80,7 +80,7 @@
std::unique_ptr<rtc::PlatformThread> thread_;
ModuleList modules_;
- std::queue<rtc::QueuedTask*> queue_;
+ std::queue<QueuedTask*> queue_;
bool stop_;
const char* thread_name_;
};
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 67b4290..cd9d179 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -533,6 +533,7 @@
deps = [
":macromagic",
":ptr_util",
+ "../api/task_queue",
"system:rtc_export",
"//third_party/abseil-cpp/absl/memory",
]
diff --git a/rtc_base/task_queue.h b/rtc_base/task_queue.h
index 0f2d219..41fcf41 100644
--- a/rtc_base/task_queue.h
+++ b/rtc_base/task_queue.h
@@ -17,6 +17,7 @@
#include <utility>
#include "absl/memory/memory.h"
+#include "api/task_queue/queued_task.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/scoped_ref_ptr.h"
#include "rtc_base/system/rtc_export.h"
@@ -24,24 +25,9 @@
namespace rtc {
-// Base interface for asynchronously executed tasks.
-// The interface basically consists of a single function, Run(), that executes
-// on the target queue. For more details see the Run() method and TaskQueue.
-class QueuedTask {
- public:
- QueuedTask() {}
- virtual ~QueuedTask() {}
-
- // Main routine that will run when the task is executed on the desired queue.
- // The task should return |true| to indicate that it should be deleted or
- // |false| to indicate that the queue should consider ownership of the task
- // having been transferred. Returning |false| can be useful if a task has
- // re-posted itself to a different queue or is otherwise being re-used.
- virtual bool Run() = 0;
-
- private:
- RTC_DISALLOW_COPY_AND_ASSIGN(QueuedTask);
-};
+// TODO(danilchap): Remove the alias when all of webrtc is updated to use
+// webrtc::QueuedTask directly.
+using ::webrtc::QueuedTask;
// Simple implementation of QueuedTask for use with rtc::Bind and lambdas.
template <class Closure>