forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git/+log/854d164..e5dcf5c $ git log 854d164..e5dcf5c --date=short --no-merges --format=%ad %ae %s 2016-08-30 perkj@webrtc.org Do not build task_queue.cc and include from webrtc_overrides in Chrome. This is step 2 of the plan below. 2016-08-30 honghaiz@webrtc.org Add a switch to redetermine role when ICE restarts. 2016-08-30 hbos@webrtc.org Making hbos and hta OWNERS of webrtc/api/rtcstats*. 2016-08-30 kjellander@webrtc.org MB: Flip iOS bots to GN by default 2016-08-30 hbos@webrtc.org RTCStatsCollector and RTCPeerConnectionStats added. Override webrtc task_queue.cc and task_queue.h. This is step 3 of the plan below. The modified plan 1. First land unmodified task_queue.h into webrtc_override in Chrome 2. Modify build files in the webrtc repo to include the task_queue.h and task_queue.cc from webrtc_overrides. This will breaks webrtc Chrome FYI. 3. Combine a roll of webrtc to Chrome and this cl into one cl. The combined cl will roll in build files from 2 and add task_queue.cc in webrtc_overrides and build task_queue_unittest.cc as part of content_unittests to test task_queue.cc in webrtc_overrides. 4... Start using task queues in webrtc........ TBR=tommi@chromium.org CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_archive_rel_ng;master.tryserver.chromium.mac:mac_chromium_archive_rel_ng BUG=webrtc:5687 Review-Url: https://codereview.chromium.org/2295723004 Cr-Commit-Position: refs/heads/master@{#415579}
- Loading branch information
perkj
authored and
Commit bot
committed
Aug 31, 2016
1 parent
85f727b
commit 103f054
Showing
4 changed files
with
145 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright 2016 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. | ||
*/ | ||
|
||
#include "third_party/webrtc_overrides/webrtc/base/task_queue.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/lazy_instance.h" | ||
#include "base/threading/thread.h" | ||
#include "base/threading/thread_local.h" | ||
|
||
namespace rtc { | ||
namespace { | ||
|
||
void RunTask(std::unique_ptr<QueuedTask> task) { | ||
if (!task->Run()) | ||
task.release(); | ||
} | ||
|
||
class PostAndReplyTask : public QueuedTask { | ||
public: | ||
PostAndReplyTask( | ||
std::unique_ptr<QueuedTask> task, | ||
std::unique_ptr<QueuedTask> reply, | ||
const scoped_refptr<base::SingleThreadTaskRunner>& reply_task_runner) | ||
: task_(std::move(task)), | ||
reply_(std::move(reply)), | ||
reply_task_runner_(reply_task_runner) {} | ||
|
||
~PostAndReplyTask() override {} | ||
|
||
private: | ||
bool Run() override { | ||
if (!task_->Run()) | ||
task_.release(); | ||
|
||
reply_task_runner_->PostTask(FROM_HERE, | ||
base::Bind(&RunTask, base::Passed(&reply_))); | ||
return true; | ||
} | ||
|
||
std::unique_ptr<QueuedTask> task_; | ||
std::unique_ptr<QueuedTask> reply_; | ||
scoped_refptr<base::SingleThreadTaskRunner> reply_task_runner_; | ||
}; | ||
|
||
// A lazily created thread local storage for quick access to a TaskQueue. | ||
base::LazyInstance<base::ThreadLocalPointer<TaskQueue>>::Leaky lazy_tls_ptr = | ||
LAZY_INSTANCE_INITIALIZER; | ||
|
||
} // namespace | ||
|
||
bool TaskQueue::IsCurrent() const { | ||
return Current() == this; | ||
} | ||
|
||
class TaskQueue::WorkerThread : public base::Thread { | ||
public: | ||
WorkerThread(const char* queue_name, TaskQueue* queue); | ||
~WorkerThread() override; | ||
|
||
private: | ||
virtual void Init() override; | ||
|
||
TaskQueue* const queue_; | ||
}; | ||
|
||
TaskQueue::WorkerThread::WorkerThread(const char* queue_name, TaskQueue* queue) | ||
: base::Thread(queue_name), queue_(queue) {} | ||
|
||
void TaskQueue::WorkerThread::Init() { | ||
lazy_tls_ptr.Pointer()->Set(queue_); | ||
} | ||
|
||
TaskQueue::WorkerThread::~WorkerThread() { | ||
DCHECK(!Thread::IsRunning()); | ||
} | ||
|
||
TaskQueue::TaskQueue(const char* queue_name) | ||
: thread_( | ||
std::unique_ptr<WorkerThread>(new WorkerThread(queue_name, this))) { | ||
DCHECK(queue_name); | ||
bool result = thread_->Start(); | ||
CHECK(result); | ||
} | ||
|
||
TaskQueue::~TaskQueue() { | ||
DCHECK(!IsCurrent()); | ||
thread_->Stop(); | ||
} | ||
|
||
// static | ||
TaskQueue* TaskQueue::Current() { | ||
return lazy_tls_ptr.Pointer()->Get(); | ||
} | ||
|
||
// static | ||
bool TaskQueue::IsCurrent(const char* queue_name) { | ||
TaskQueue* current = Current(); | ||
return current && current->thread_->thread_name().compare(queue_name) == 0; | ||
} | ||
|
||
void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) { | ||
thread_->task_runner()->PostTask(FROM_HERE, | ||
base::Bind(&RunTask, base::Passed(&task))); | ||
} | ||
|
||
void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, | ||
uint32_t milliseconds) { | ||
thread_->task_runner()->PostDelayedTask( | ||
FROM_HERE, base::Bind(&RunTask, base::Passed(&task)), | ||
base::TimeDelta::FromMilliseconds(milliseconds)); | ||
} | ||
|
||
void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, | ||
std::unique_ptr<QueuedTask> reply, | ||
TaskQueue* reply_queue) { | ||
PostTask(std::unique_ptr<QueuedTask>(new PostAndReplyTask( | ||
std::move(task), std::move(reply), reply_queue->thread_->task_runner()))); | ||
} | ||
|
||
void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, | ||
std::unique_ptr<QueuedTask> reply) { | ||
thread_->task_runner()->PostTaskAndReply( | ||
FROM_HERE, base::Bind(&RunTask, base::Passed(&task)), | ||
base::Bind(&RunTask, base::Passed(&reply))); | ||
} | ||
|
||
} // namespace rtc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters