Reland of Change ProcessThread's task type to be the one from TaskQueue. (patchset #1 id:1 of https://codereview.webrtc.org/2020783003/ )

Reason for revert:
Reland. It was a false alarm.

Original issue's description:
> Revert of Change ProcessThread's task type to be the one from TaskQueue. (patchset #3 id:80001 of https://codereview.webrtc.org/2016043003/ )
>
> Reason for revert:
> Downstream issues
>
> Original issue's description:
> > Change ProcessThread's task type to be the one from TaskQueue.
> > ProcessThread will eventually be replaced by TaskQueue, so this is the first little step.
> >
> > BUG=
> > R=magjed@webrtc.org
> >
> > Committed: https://crrev.com/400a276c8a0b299190ff17a81edd8780a26d63d3
> > Cr-Commit-Position: refs/heads/master@{#12952}
>
> TBR=magjed@webrtc.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=
>
> Committed: https://crrev.com/641455176a1241dea6dda7071ba4162f41a0b5fc
> Cr-Commit-Position: refs/heads/master@{#12953}

TBR=magjed@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.webrtc.org/2017333002
Cr-Commit-Position: refs/heads/master@{#12954}
This commit is contained in:
tommi
2016-05-28 14:57:15 -07:00
committed by Commit bot
parent 641455176a
commit 435f98bc90
8 changed files with 31 additions and 19 deletions

View File

@ -41,6 +41,7 @@ source_set("utility") {
deps = [ deps = [
"../..:webrtc_common", "../..:webrtc_common",
"../../base:rtc_task_queue",
"../../common_audio", "../../common_audio",
"../../system_wrappers", "../../system_wrappers",
"../audio_coding", "../audio_coding",

View File

@ -28,14 +28,14 @@ class MockProcessThread : public ProcessThread {
MOCK_METHOD0(Start, void()); MOCK_METHOD0(Start, void());
MOCK_METHOD0(Stop, void()); MOCK_METHOD0(Stop, void());
MOCK_METHOD1(WakeUp, void(Module* module)); MOCK_METHOD1(WakeUp, void(Module* module));
MOCK_METHOD1(PostTask, void(ProcessTask* task)); MOCK_METHOD1(PostTask, void(rtc::QueuedTask* task));
MOCK_METHOD1(RegisterModule, void(Module* module)); MOCK_METHOD1(RegisterModule, void(Module* module));
MOCK_METHOD1(DeRegisterModule, void(Module* module)); MOCK_METHOD1(DeRegisterModule, void(Module* module));
// MOCK_METHOD1 gets confused with mocking this method, so we work around it // 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 // by overriding the method from the interface and forwarding the call to a
// mocked, simpler method. // mocked, simpler method.
void PostTask(std::unique_ptr<ProcessTask> task) /* override */ { void PostTask(std::unique_ptr<rtc::QueuedTask> task) /*override*/ {
PostTask(task.get()); PostTask(task.get());
} }
}; };

View File

@ -15,17 +15,23 @@
#include "webrtc/typedefs.h" #include "webrtc/typedefs.h"
#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 "webrtc/base/task_queue.h"
#else
namespace rtc {
class QueuedTask;
}
#endif
namespace webrtc { namespace webrtc {
class Module; class Module;
class ProcessTask { // TODO(tommi): ProcessThread probably doesn't need to be a virtual
public: // interface. There exists one override besides ProcessThreadImpl,
ProcessTask() {} // MockProcessThread, but when looking at how it is used, it seems
virtual ~ProcessTask() {} // a nullptr might suffice (or simply an actual ProcessThread instance).
virtual void Run() = 0;
};
class ProcessThread { class ProcessThread {
public: public:
virtual ~ProcessThread(); virtual ~ProcessThread();
@ -51,7 +57,7 @@ class ProcessThread {
// construction thread of the ProcessThread instance, if the task did not // 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 // get a chance to run (e.g. posting the task while shutting down or when
// the thread never runs). // the thread never runs).
virtual void PostTask(std::unique_ptr<ProcessTask> task) = 0; virtual void PostTask(std::unique_ptr<rtc::QueuedTask> task) = 0;
// Adds a module that will start to receive callbacks on the worker thread. // Adds a module that will start to receive callbacks on the worker thread.
// Can be called from any thread. // Can be called from any thread.

View File

@ -11,6 +11,7 @@
#include "webrtc/modules/utility/source/process_thread_impl.h" #include "webrtc/modules/utility/source/process_thread_impl.h"
#include "webrtc/base/checks.h" #include "webrtc/base/checks.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/timeutils.h" #include "webrtc/base/timeutils.h"
#include "webrtc/modules/include/module.h" #include "webrtc/modules/include/module.h"
#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/logging.h"
@ -119,7 +120,7 @@ void ProcessThreadImpl::WakeUp(Module* module) {
wake_up_->Set(); wake_up_->Set();
} }
void ProcessThreadImpl::PostTask(std::unique_ptr<ProcessTask> task) { void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) {
// Allowed to be called on any thread. // Allowed to be called on any thread.
{ {
rtc::CritScope lock(&lock_); rtc::CritScope lock(&lock_);
@ -218,7 +219,7 @@ bool ProcessThreadImpl::Process() {
} }
while (!queue_.empty()) { while (!queue_.empty()) {
ProcessTask* task = queue_.front(); rtc::QueuedTask* task = queue_.front();
queue_.pop(); queue_.pop();
lock_.Leave(); lock_.Leave();
task->Run(); task->Run();

View File

@ -33,7 +33,7 @@ class ProcessThreadImpl : public ProcessThread {
void Stop() override; void Stop() override;
void WakeUp(Module* module) override; void WakeUp(Module* module) override;
void PostTask(std::unique_ptr<ProcessTask> task) override; void PostTask(std::unique_ptr<rtc::QueuedTask> task) override;
void RegisterModule(Module* module) override; void RegisterModule(Module* module) override;
void DeRegisterModule(Module* module) override; void DeRegisterModule(Module* module) override;
@ -75,8 +75,7 @@ class ProcessThreadImpl : public ProcessThread {
std::unique_ptr<rtc::PlatformThread> thread_; std::unique_ptr<rtc::PlatformThread> thread_;
ModuleList modules_; ModuleList modules_;
// TODO(tommi): Support delayed tasks. std::queue<rtc::QueuedTask*> queue_;
std::queue<ProcessTask*> queue_;
bool stop_; bool stop_;
const char* thread_name_; const char* thread_name_;
}; };

View File

@ -13,6 +13,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/timeutils.h" #include "webrtc/base/timeutils.h"
#include "webrtc/modules/include/module.h" #include "webrtc/modules/include/module.h"
#include "webrtc/modules/utility/source/process_thread_impl.h" #include "webrtc/modules/utility/source/process_thread_impl.h"
@ -33,10 +34,13 @@ class MockModule : public Module {
MOCK_METHOD1(ProcessThreadAttached, void(ProcessThread*)); MOCK_METHOD1(ProcessThreadAttached, void(ProcessThread*));
}; };
class RaiseEventTask : public ProcessTask { class RaiseEventTask : public rtc::QueuedTask {
public: public:
RaiseEventTask(EventWrapper* event) : event_(event) {} RaiseEventTask(EventWrapper* event) : event_(event) {}
void Run() override { event_->Set(); } bool Run() override {
event_->Set();
return true;
}
private: private:
EventWrapper* event_; EventWrapper* event_;

View File

@ -14,6 +14,7 @@
'dependencies': [ 'dependencies': [
'audio_coding_module', 'audio_coding_module',
'media_file', 'media_file',
'<(webrtc_root)/base/base.gyp:rtc_task_queue',
'<(webrtc_root)/common_audio/common_audio.gyp:common_audio', '<(webrtc_root)/common_audio/common_audio.gyp:common_audio',
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
], ],

View File

@ -195,7 +195,7 @@ class ProcessThreadMock : public ProcessThread {
MOCK_METHOD1(WakeUp, void(Module* module)); MOCK_METHOD1(WakeUp, void(Module* module));
MOCK_METHOD1(RegisterModule, void(Module* module)); MOCK_METHOD1(RegisterModule, void(Module* module));
MOCK_METHOD1(DeRegisterModule, void(Module* module)); MOCK_METHOD1(DeRegisterModule, void(Module* module));
void PostTask(std::unique_ptr<ProcessTask> task) {} void PostTask(std::unique_ptr<rtc::QueuedTask> task) /*override*/ {}
}; };
class TestBasicJitterBuffer : public ::testing::TestWithParam<std::string>, class TestBasicJitterBuffer : public ::testing::TestWithParam<std::string>,