blob: 188ffe72b5f8adea6208635d68263b3139811000 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/test/ordered_simple_task_runner.h"
#include <algorithm>
#include <deque>
#include "base/logging.h"
namespace {
bool TestPendingTaskComparator(const base::TestPendingTask& lhs,
const base::TestPendingTask& rhs) {
return lhs.ShouldRunBefore(rhs);
}
}
namespace cc {
OrderedSimpleTaskRunner::OrderedSimpleTaskRunner() {}
OrderedSimpleTaskRunner::~OrderedSimpleTaskRunner() {}
void OrderedSimpleTaskRunner::RunPendingTasks() {
DCHECK(thread_checker_.CalledOnValidThread());
// Swap with a local variable to avoid re-entrancy problems.
std::deque<base::TestPendingTask> tasks_to_run;
tasks_to_run.swap(pending_tasks_);
std::stable_sort(tasks_to_run.begin(),
tasks_to_run.end(),
TestPendingTaskComparator);
for (std::deque<base::TestPendingTask>::iterator it = tasks_to_run.begin();
it != tasks_to_run.end(); ++it) {
it->task.Run();
}
}
} // namespace cc
|