Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Unified Diff: cc/trees/blocking_task_runner.cc

Issue 266353003: aw: Ubercomp mega patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/blocking_task_runner.h ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/blocking_task_runner.cc
diff --git a/cc/trees/blocking_task_runner.cc b/cc/trees/blocking_task_runner.cc
index 576aa9b1bf9360a0949a84e2db5c659ca40c2c53..8f60a861de655fec95f6a1dc185b31bb67939f8f 100644
--- a/cc/trees/blocking_task_runner.cc
+++ b/cc/trees/blocking_task_runner.cc
@@ -12,16 +12,13 @@
namespace cc {
-typedef std::pair<base::SingleThreadTaskRunner*,
- scoped_refptr<BlockingTaskRunner> > TaskRunnerPair;
-
struct TaskRunnerPairs {
static TaskRunnerPairs* GetInstance() {
return Singleton<TaskRunnerPairs>::get();
}
base::Lock lock;
- std::vector<TaskRunnerPair> pairs;
+ std::vector<scoped_refptr<BlockingTaskRunner> > pairs;
private:
friend struct DefaultSingletonTraits<TaskRunnerPairs>;
@@ -30,40 +27,35 @@ struct TaskRunnerPairs {
// static
scoped_refptr<BlockingTaskRunner> BlockingTaskRunner::current() {
TaskRunnerPairs* task_runners = TaskRunnerPairs::GetInstance();
+ base::PlatformThreadId thread_id = base::PlatformThread::CurrentId();
base::AutoLock lock(task_runners->lock);
+ // TODO(boliu): Leaks
for (size_t i = 0; i < task_runners->pairs.size(); ++i) {
- if (task_runners->pairs[i].first->HasOneRef()) {
- // The SingleThreadTaskRunner is kept alive by its MessageLoop, and we
- // hold a second reference in the TaskRunnerPairs array. If the
- // SingleThreadTaskRunner has one ref, then it is being held alive only
- // by the BlockingTaskRunner and the MessageLoop is gone, so drop the
- // BlockingTaskRunner from the TaskRunnerPairs array along with the
- // SingleThreadTaskRunner.
- task_runners->pairs.erase(task_runners->pairs.begin() + i);
- --i;
- }
- }
-
- scoped_refptr<base::SingleThreadTaskRunner> current =
- base::MessageLoopProxy::current();
- for (size_t i = 0; i < task_runners->pairs.size(); ++i) {
- if (task_runners->pairs[i].first == current.get())
- return task_runners->pairs[i].second.get();
+ if (task_runners->pairs[i]->thread_id_ == thread_id)
+ return task_runners->pairs[i];
}
- scoped_refptr<BlockingTaskRunner> runner = new BlockingTaskRunner(current);
- task_runners->pairs.push_back(TaskRunnerPair(current, runner));
+ scoped_refptr<BlockingTaskRunner> runner =
+ new BlockingTaskRunner(base::MessageLoopProxy::current());
+ task_runners->pairs.push_back(runner);
return runner;
}
BlockingTaskRunner::BlockingTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : task_runner_(task_runner), capture_(0) {}
+ : thread_id_(base::PlatformThread::CurrentId()),
+ task_runner_(task_runner),
+ capture_(0) {
+}
BlockingTaskRunner::~BlockingTaskRunner() {}
+bool BlockingTaskRunner::BelongsToCurrentThread() {
+ return base::PlatformThread::CurrentId() == thread_id_;
+}
+
bool BlockingTaskRunner::PostTask(const tracked_objects::Location& from_here,
const base::Closure& task) {
base::AutoLock lock(lock_);
« no previous file with comments | « cc/trees/blocking_task_runner.h ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698