OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_SCHEDULER_SEQUENCE_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SEQUENCE_H_ |
6 #define BASE_TASK_SCHEDULER_SEQUENCE_H_ | 6 #define BASE_TASK_SCHEDULER_SEQUENCE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <queue> | 11 #include <queue> |
11 | 12 |
12 #include "base/base_export.h" | 13 #include "base/base_export.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/task_scheduler/scheduler_lock.h" | 16 #include "base/task_scheduler/scheduler_lock.h" |
17 #include "base/task_scheduler/sequence_sort_key.h" | 17 #include "base/task_scheduler/sequence_sort_key.h" |
18 #include "base/task_scheduler/task.h" | 18 #include "base/task_scheduler/task.h" |
19 #include "base/task_scheduler/task_traits.h" | 19 #include "base/task_scheduler/task_traits.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 // A sequence holds tasks that must be executed in posting order. | 24 // A sequence holds tasks that must be executed in posting order. |
25 // This class is thread-safe. | 25 // This class is thread-safe. |
26 class BASE_EXPORT Sequence : public RefCountedThreadSafe<Sequence> { | 26 class BASE_EXPORT Sequence : public RefCountedThreadSafe<Sequence> { |
27 public: | 27 public: |
28 Sequence(); | 28 Sequence(); |
29 | 29 |
30 // Adds |task| at the end of the sequence's queue. Returns true if the | 30 // Adds |task| at the end of the sequence's queue. Returns true if the |
31 // sequence was empty before this operation. | 31 // sequence was empty before this operation. |
32 bool PushTask(scoped_ptr<Task> task); | 32 bool PushTask(std::unique_ptr<Task> task); |
33 | 33 |
34 // Returns the task in front of the sequence's queue, if any. | 34 // Returns the task in front of the sequence's queue, if any. |
35 const Task* PeekTask() const; | 35 const Task* PeekTask() const; |
36 | 36 |
37 // Removes the task in front of the sequence's queue. Returns true if the | 37 // Removes the task in front of the sequence's queue. Returns true if the |
38 // sequence is empty after this operation. Cannot be called on an empty | 38 // sequence is empty after this operation. Cannot be called on an empty |
39 // sequence. | 39 // sequence. |
40 bool PopTask(); | 40 bool PopTask(); |
41 | 41 |
42 // Returns a SequenceSortKey representing the priority of the sequence. Cannot | 42 // Returns a SequenceSortKey representing the priority of the sequence. Cannot |
43 // be called on an empty sequence. | 43 // be called on an empty sequence. |
44 SequenceSortKey GetSortKey() const; | 44 SequenceSortKey GetSortKey() const; |
45 | 45 |
46 private: | 46 private: |
47 friend class RefCountedThreadSafe<Sequence>; | 47 friend class RefCountedThreadSafe<Sequence>; |
48 ~Sequence(); | 48 ~Sequence(); |
49 | 49 |
50 // Synchronizes access to all members. | 50 // Synchronizes access to all members. |
51 mutable SchedulerLock lock_; | 51 mutable SchedulerLock lock_; |
52 | 52 |
53 // Queue of tasks to execute. | 53 // Queue of tasks to execute. |
54 std::queue<scoped_ptr<Task>> queue_; | 54 std::queue<std::unique_ptr<Task>> queue_; |
55 | 55 |
56 // Number of tasks contained in the sequence for each priority. | 56 // Number of tasks contained in the sequence for each priority. |
57 size_t num_tasks_per_priority_[static_cast<int>(TaskPriority::HIGHEST) + 1] = | 57 size_t num_tasks_per_priority_[static_cast<int>(TaskPriority::HIGHEST) + 1] = |
58 {}; | 58 {}; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(Sequence); | 60 DISALLOW_COPY_AND_ASSIGN(Sequence); |
61 }; | 61 }; |
62 | 62 |
63 } // namespace internal | 63 } // namespace internal |
64 } // namespace base | 64 } // namespace base |
65 | 65 |
66 #endif // BASE_TASK_SCHEDULER_SEQUENCE_H_ | 66 #endif // BASE_TASK_SCHEDULER_SEQUENCE_H_ |
OLD | NEW |