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 #ifndef BASE_TASK_SCHEDULER_SEQUENCE_H_ | |
6 #define BASE_TASK_SCHEDULER_SEQUENCE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <queue> | |
11 | |
12 #include "base/base_export.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/task_scheduler/scheduler_lock.h" | |
17 #include "base/task_scheduler/sequence_sort_key.h" | |
18 #include "base/task_scheduler/task.h" | |
fdoray
2016/02/11 17:30:33
#include "task_traits.h" for kNumTaskPriorities.
fdoray
2016/02/12 04:16:19
Done.
| |
19 | |
20 namespace base { | |
21 namespace task_scheduler { | |
22 | |
23 // A sequence holds tasks that must be executed in posting order. This class is | |
24 // thread-safe. | |
25 class BASE_EXPORT Sequence : public RefCountedThreadSafe<Sequence> { | |
26 public: | |
27 Sequence(); | |
28 | |
29 // Adds |task| at the end of the sequence's queue. |prev_num_tasks| is set to | |
30 // the number of tasks that were in the sequence prior to the push. | |
31 void PushTask(scoped_ptr<Task> task, size_t* prev_num_tasks); | |
32 | |
33 // Returns the sequence in front of the sequence's queue, if any. | |
34 const Task* PeekTask(); | |
35 | |
36 // Removes the task in front of the sequence's queue. |new_num_tasks| is set | |
37 // to the number of tasks that are in the sequence right after the pop. This | |
38 // cannot be called on an empty sequence. | |
39 void PopTask(size_t* new_num_tasks); | |
40 | |
41 // Returns a sort key to use when inserting the sequence in a priority queue. | |
42 // This cannot be called on an empty sequence. | |
43 SequenceSortKey GetSortKey(); | |
44 | |
45 private: | |
46 friend class RefCountedThreadSafe<Sequence>; | |
47 ~Sequence(); | |
48 | |
49 // Controls access to all members. | |
50 SchedulerLock lock_; | |
51 | |
52 // Queue of tasks to execute. | |
53 std::queue<scoped_ptr<Task>> queue_; | |
54 | |
55 // Number of tasks contained in the sequence for each priority. | |
56 size_t num_tasks_per_priority_[kNumTaskPriorities]; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(Sequence); | |
59 }; | |
60 | |
61 } // namespace task_scheduler | |
62 } // namespace base | |
63 | |
64 #endif // BASE_TASK_SCHEDULER_SEQUENCE_H_ | |
OLD | NEW |