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}
This commit is contained in:
Danil Chapovalov 2019-01-14 14:29:18 +01:00 committed by Commit Bot
parent 645df9e3b5
commit 959e9b6b57
9 changed files with 63 additions and 37 deletions

16
api/task_queue/BUILD.gn Normal file
View File

@ -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",
]
}

View File

@ -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_

View File

@ -26,10 +26,10 @@ rtc_static_library("utility") {
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",
]

View File

@ -28,14 +28,14 @@ class MockProcessThread : public ProcessThread {
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());
}
};

View File

@ -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 @@ class ProcessThread {
// 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.

View File

@ -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 @@ void ProcessThreadImpl::WakeUp(Module* module) {
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 @@ bool ProcessThreadImpl::Process() {
}
while (!queue_.empty()) {
rtc::QueuedTask* task = queue_.front();
QueuedTask* task = queue_.front();
queue_.pop();
lock_.Leave();
task->Run();

View File

@ -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 @@ class ProcessThreadImpl : public ProcessThread {
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 @@ class ProcessThreadImpl : public ProcessThread {
std::unique_ptr<rtc::PlatformThread> thread_;
ModuleList modules_;
std::queue<rtc::QueuedTask*> queue_;
std::queue<QueuedTask*> queue_;
bool stop_;
const char* thread_name_;
};

View File

@ -533,6 +533,7 @@ rtc_source_set("rtc_task_queue_api") {
deps = [
":macromagic",
":ptr_util",
"../api/task_queue",
"system:rtc_export",
"//third_party/abseil-cpp/absl/memory",
]

View File

@ -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>