OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/task_scheduler/utils.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/callback.h" | |
10 #include "base/logging.h" | |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/task_scheduler/priority_queue.h" | |
13 #include "base/task_scheduler/scheduler_task_executor.h" | |
14 #include "base/task_scheduler/sequence_sort_key.h" | |
15 #include "base/task_scheduler/task_tracker.h" | |
16 #include "base/time/time.h" | |
17 | |
18 namespace base { | |
19 namespace internal { | |
20 | |
21 bool PostTaskHelper(const tracked_objects::Location& posted_from, | |
22 const Closure& closure, | |
23 const TaskTraits& traits, | |
24 const TimeDelta& delay, | |
25 scoped_refptr<Sequence> sequence, | |
26 SchedulerTaskExecutor* executor, | |
27 TaskTracker* task_tracker) { | |
28 DCHECK(!closure.is_null()); | |
29 DCHECK(sequence); | |
30 DCHECK(executor); | |
31 DCHECK(task_tracker); | |
32 | |
33 // TODO(fdoray): Support delayed tasks. | |
34 DCHECK(delay.is_zero()); | |
35 | |
36 std::unique_ptr<Task> task(new Task(posted_from, closure, traits)); | |
37 | |
38 if (!task_tracker->WillPostTask(task.get())) | |
39 return false; | |
40 | |
41 executor->PostTaskWithSequence(std::move(task), std::move(sequence)); | |
42 return true; | |
43 } | |
44 | |
45 bool PostTaskWithSequenceHelper(std::unique_ptr<Task> task, | |
46 scoped_refptr<Sequence> sequence, | |
47 PriorityQueue* priority_queue) { | |
48 DCHECK(task); | |
49 DCHECK(sequence); | |
50 DCHECK(priority_queue); | |
51 | |
52 // Verify that we are passed |task|'s delayed run time (i.e. |task| is ready | |
53 // to run). | |
54 DCHECK_LE(task->delayed_run_time, TimeTicks::Now()); | |
gab
2016/04/14 19:34:16
Since the same DCHECK is already in PostTaskWithSe
fdoray
2016/04/14 23:46:59
Done. Removed the DCHECK from STP::PostTaskWithSeq
| |
55 | |
56 const bool sequence_was_empty = sequence->PushTask(std::move(task)); | |
57 if (sequence_was_empty) { | |
58 // Insert |sequence| in |priority_queue| if it was empty before |task| was | |
59 // inserted into it. When that's not the case, one of these must be true: | |
60 // - |sequence| is already in a PriorityQueue, or, | |
61 // - A worker thread is running a Task from |sequence|. It will insert | |
62 // |sequence| in a PriorityQueue once it's done running the Task. | |
63 const auto sequence_sort_key = sequence->GetSortKey(); | |
64 priority_queue->BeginTransaction()->Push( | |
65 WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence), | |
66 sequence_sort_key))); | |
67 } | |
68 | |
69 return sequence_was_empty; | |
70 } | |
71 | |
72 } // namespace internal | |
73 } // namespace base | |
OLD | NEW |