| 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, | 33 WorkQueue(TaskQueueImpl* task_queue, const char* name); |
| 34 const char* name, | |
| 35 TaskQueueImpl::Task::ComparatorFn queue_comparator); | |
| 36 ~WorkQueue(); | 34 ~WorkQueue(); |
| 37 | 35 |
| 38 // Associates this work queue with the given work queue sets. This must be | 36 // Associates this work queue with the given work queue sets. This must be |
| 39 // called before any tasks can be inserted into this work queue. | 37 // called before any tasks can be inserted into this work queue. |
| 40 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); | 38 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); |
| 41 | 39 |
| 42 // Assigns the current set index. | 40 // Assigns the current set index. |
| 43 void AssignSetIndex(size_t work_queue_set_index); | 41 void AssignSetIndex(size_t work_queue_set_index); |
| 44 | 42 |
| 45 void AsValueInto(base::trace_event::TracedValue* state) const; | 43 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 46 | 44 |
| 47 // Returns true if the |work_queue_| is empty. This method ignores any fences. | 45 // Returns true if the |work_queue_| is empty. This method ignores any fences. |
| 48 bool Empty() const { return work_queue_.empty(); } | 46 bool Empty() const { return work_queue_.empty(); } |
| 49 | 47 |
| 50 // If the |work_queue_| isn't empty and a fence hasn't been reached, | 48 // If the |work_queue_| isn't empty and a fence hasn't been reached, |
| 51 // |enqueue_order| gets set to the enqueue order of the front task and the | 49 // |enqueue_order| gets set to the enqueue order of the front task and the |
| 52 // function returns true. Otherwise the function returns false. | 50 // function returns true. Otherwise the function returns false. |
| 53 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; | 51 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; |
| 54 | 52 |
| 55 // Returns the first task in this queue or null if the queue is empty. This | 53 // Returns the first task in this queue or null if the queue is empty. This |
| 56 // method ignores any fences. | 54 // method ignores any fences. |
| 57 const TaskQueueImpl::Task* GetFrontTask() const; | 55 const TaskQueueImpl::Task* GetFrontTask() const; |
| 58 | 56 |
| 59 // Returns the first task in this queue or null if the queue is empty. This | 57 // Returns the last task in this queue or null if the queue is empty. This |
| 60 // method ignores any fences. | 58 // method ignores any fences. |
| 61 const TaskQueueImpl::Task* GetBackTask() const; | 59 const TaskQueueImpl::Task* GetBackTask() const; |
| 62 | 60 |
| 63 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it | 61 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it |
| 64 // informs the WorkQueueSets if the head changed. | 62 // informs the WorkQueueSets if the head changed. |
| 65 void Push(TaskQueueImpl::Task task); | 63 void Push(TaskQueueImpl::Task task); |
| 66 | 64 |
| 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 | |
| 77 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been | 65 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been |
| 78 // reached it informs the WorkQueueSets if the head changed. Assumes | 66 // reached it informs the WorkQueueSets if the head changed. Assumes |
| 79 // |task_queue_->any_thread_lock_| is locked. | 67 // |task_queue_->any_thread_lock_| is locked. |
| 80 void SwapLocked(TaskQueueImpl::ComparatorQueue& incoming_queue); | 68 void SwapLocked(std::queue<TaskQueueImpl::Task>& incoming_queue); |
| 81 | 69 |
| 82 size_t Size() const { return work_queue_.size(); } | 70 size_t Size() const { return work_queue_.size(); } |
| 83 | 71 |
| 84 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the | 72 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the |
| 85 // task removed had an enqueue order >= the current fence then WorkQueue | 73 // task removed had an enqueue order >= the current fence then WorkQueue |
| 86 // pretends to be empty as far as the WorkQueueSets is concrned. | 74 // pretends to be empty as far as the WorkQueueSets is concrned. |
| 87 TaskQueueImpl::Task TakeTaskFromWorkQueue(); | 75 TaskQueueImpl::Task TakeTaskFromWorkQueue(); |
| 88 | 76 |
| 89 const char* name() const { return name_; } | 77 const char* name() const { return name_; } |
| 90 | 78 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 // empty, then the real value is reported to WorkQueueSets. Returns true if | 101 // empty, then the real value is reported to WorkQueueSets. Returns true if |
| 114 // any tasks where unblocked. | 102 // any tasks where unblocked. |
| 115 bool RemoveFence(); | 103 bool RemoveFence(); |
| 116 | 104 |
| 117 // Returns true if any tasks are blocked by the fence. Returns true if the | 105 // Returns true if any tasks are blocked by the fence. Returns true if the |
| 118 // queue is empty and fence has been set (i.e. future tasks would be blocked). | 106 // queue is empty and fence has been set (i.e. future tasks would be blocked). |
| 119 // Otherwise returns false. | 107 // Otherwise returns false. |
| 120 bool BlockedByFence() const; | 108 bool BlockedByFence() const; |
| 121 | 109 |
| 122 private: | 110 private: |
| 123 TaskQueueImpl::ComparatorQueue work_queue_; | 111 std::queue<TaskQueueImpl::Task> work_queue_; |
| 124 WorkQueueSets* work_queue_sets_; // NOT OWNED. | 112 WorkQueueSets* work_queue_sets_; // NOT OWNED. |
| 125 TaskQueueImpl* task_queue_; // NOT OWNED. | 113 TaskQueueImpl* task_queue_; // NOT OWNED. |
| 126 size_t work_queue_set_index_; | 114 size_t work_queue_set_index_; |
| 127 const char* name_; | 115 const char* name_; |
| 128 EnqueueOrder fence_; | 116 EnqueueOrder fence_; |
| 129 | 117 |
| 130 DISALLOW_COPY_AND_ASSIGN(WorkQueue); | 118 DISALLOW_COPY_AND_ASSIGN(WorkQueue); |
| 131 }; | 119 }; |
| 132 | 120 |
| 133 } // namespace internal | 121 } // namespace internal |
| 134 } // namespace scheduler | 122 } // namespace scheduler |
| 135 } // namespace blink | 123 } // namespace blink |
| 136 | 124 |
| 137 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ | 125 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ |
| OLD | NEW |