OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 12 matching lines...) Expand all Loading... |
23 // now. It interfaces deeply with WorkQueueSets which keeps track of which queue | 23 // now. It interfaces deeply with WorkQueueSets which keeps track of which queue |
24 // (with a given priority) contains the oldest task. | 24 // (with a given priority) contains the oldest task. |
25 // | 25 // |
26 // If a fence is inserted, WorkQueue behaves normally up until | 26 // If a fence is inserted, WorkQueue behaves normally up until |
27 // TakeTaskFromWorkQueue reaches or exceeds the fence. At that point it the | 27 // TakeTaskFromWorkQueue reaches or exceeds the fence. At that point it the |
28 // API subset used by WorkQueueSets pretends the WorkQueue is empty until the | 28 // API subset used by WorkQueueSets pretends the WorkQueue is empty until the |
29 // fence is removed. This functionality is a primitive intended for use by | 29 // fence is removed. This functionality is a primitive intended for use by |
30 // throttling mechanisms. | 30 // throttling mechanisms. |
31 class BLINK_PLATFORM_EXPORT WorkQueue { | 31 class BLINK_PLATFORM_EXPORT WorkQueue { |
32 public: | 32 public: |
33 WorkQueue(TaskQueueImpl* task_queue, const char* name); | 33 WorkQueue(TaskQueueImpl* task_queue, |
| 34 const char* name, |
| 35 TaskQueueImpl::Task::ComparatorFn queue_comparator); |
34 ~WorkQueue(); | 36 ~WorkQueue(); |
35 | 37 |
36 // Associates this work queue with the given work queue sets. This must be | 38 // Associates this work queue with the given work queue sets. This must be |
37 // called before any tasks can be inserted into this work queue. | 39 // called before any tasks can be inserted into this work queue. |
38 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); | 40 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); |
39 | 41 |
40 // Assigns the current set index. | 42 // Assigns the current set index. |
41 void AssignSetIndex(size_t work_queue_set_index); | 43 void AssignSetIndex(size_t work_queue_set_index); |
42 | 44 |
43 void AsValueInto(base::trace_event::TracedValue* state) const; | 45 void AsValueInto(base::trace_event::TracedValue* state) const; |
44 | 46 |
45 // Returns true if the |work_queue_| is empty. This method ignores any fences. | 47 // Returns true if the |work_queue_| is empty. This method ignores any fences. |
46 bool Empty() const { return work_queue_.empty(); } | 48 bool Empty() const { return work_queue_.empty(); } |
47 | 49 |
48 // If the |work_queue_| isn't empty and a fence hasn't been reached, | 50 // If the |work_queue_| isn't empty and a fence hasn't been reached, |
49 // |enqueue_order| gets set to the enqueue order of the front task and the | 51 // |enqueue_order| gets set to the enqueue order of the front task and the |
50 // function returns true. Otherwise the function returns false. | 52 // function returns true. Otherwise the function returns false. |
51 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; | 53 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; |
52 | 54 |
53 // Returns the first task in this queue or null if the queue is empty. This | 55 // Returns the first task in this queue or null if the queue is empty. This |
54 // method ignores any fences. | 56 // method ignores any fences. |
55 const TaskQueueImpl::Task* GetFrontTask() const; | 57 const TaskQueueImpl::Task* GetFrontTask() const; |
56 | 58 |
57 // Returns the last task in this queue or null if the queue is empty. This | 59 // Returns the first task in this queue or null if the queue is empty. This |
58 // method ignores any fences. | 60 // method ignores any fences. |
59 const TaskQueueImpl::Task* GetBackTask() const; | 61 const TaskQueueImpl::Task* GetBackTask() const; |
60 | 62 |
61 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it | 63 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it |
62 // informs the WorkQueueSets if the head changed. | 64 // informs the WorkQueueSets if the head changed. |
63 void Push(TaskQueueImpl::Task task); | 65 void Push(TaskQueueImpl::Task task); |
64 | 66 |
| 67 // Removes a cancelled task from the |work_queue_|. Note |key| isn't required |
| 68 // to be the original task posted, it can be a fake key constructed by |
| 69 // TaskQueueImpl::Task::CreateFakeTaskFromHandle. |
| 70 bool CancelTask(const TaskQueueImpl::Task& key); |
| 71 |
| 72 // Returns true if |work_queue_| contains a task matching |key|. Note |key| |
| 73 // isn't required to be the original task posted, it can be a fake key |
| 74 // constructed by TaskQueueImpl::Task::CreateFakeTaskFromHandle. |
| 75 bool IsTaskPending(const TaskQueueImpl::Task& key) const; |
| 76 |
65 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been | 77 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been |
66 // reached it informs the WorkQueueSets if the head changed. Assumes | 78 // reached it informs the WorkQueueSets if the head changed. Assumes |
67 // |task_queue_->any_thread_lock_| is locked. | 79 // |task_queue_->any_thread_lock_| is locked. |
68 void SwapLocked(std::queue<TaskQueueImpl::Task>& incoming_queue); | 80 void SwapLocked(TaskQueueImpl::ComparatorQueue& incoming_queue); |
69 | 81 |
70 size_t Size() const { return work_queue_.size(); } | 82 size_t Size() const { return work_queue_.size(); } |
71 | 83 |
72 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the | 84 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the |
73 // task removed had an enqueue order >= the current fence then WorkQueue | 85 // task removed had an enqueue order >= the current fence then WorkQueue |
74 // pretends to be empty as far as the WorkQueueSets is concrned. | 86 // pretends to be empty as far as the WorkQueueSets is concrned. |
75 TaskQueueImpl::Task TakeTaskFromWorkQueue(); | 87 TaskQueueImpl::Task TakeTaskFromWorkQueue(); |
76 | 88 |
77 const char* name() const { return name_; } | 89 const char* name() const { return name_; } |
78 | 90 |
(...skipping 22 matching lines...) Expand all Loading... |
101 // empty, then the real value is reported to WorkQueueSets. Returns true if | 113 // empty, then the real value is reported to WorkQueueSets. Returns true if |
102 // any tasks where unblocked. | 114 // any tasks where unblocked. |
103 bool RemoveFence(); | 115 bool RemoveFence(); |
104 | 116 |
105 // Returns true if any tasks are blocked by the fence. Returns true if the | 117 // Returns true if any tasks are blocked by the fence. Returns true if the |
106 // queue is empty and fence has been set (i.e. future tasks would be blocked). | 118 // queue is empty and fence has been set (i.e. future tasks would be blocked). |
107 // Otherwise returns false. | 119 // Otherwise returns false. |
108 bool BlockedByFence() const; | 120 bool BlockedByFence() const; |
109 | 121 |
110 private: | 122 private: |
111 std::queue<TaskQueueImpl::Task> work_queue_; | 123 TaskQueueImpl::ComparatorQueue work_queue_; |
112 WorkQueueSets* work_queue_sets_; // NOT OWNED. | 124 WorkQueueSets* work_queue_sets_; // NOT OWNED. |
113 TaskQueueImpl* task_queue_; // NOT OWNED. | 125 TaskQueueImpl* task_queue_; // NOT OWNED. |
114 size_t work_queue_set_index_; | 126 size_t work_queue_set_index_; |
115 const char* name_; | 127 const char* name_; |
116 EnqueueOrder fence_; | 128 EnqueueOrder fence_; |
117 | 129 |
118 DISALLOW_COPY_AND_ASSIGN(WorkQueue); | 130 DISALLOW_COPY_AND_ASSIGN(WorkQueue); |
119 }; | 131 }; |
120 | 132 |
121 } // namespace internal | 133 } // namespace internal |
122 } // namespace scheduler | 134 } // namespace scheduler |
123 } // namespace blink | 135 } // namespace blink |
124 | 136 |
125 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ | 137 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ |
OLD | NEW |