Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/base/work_queue.h |
| diff --git a/third_party/WebKit/Source/platform/scheduler/base/work_queue.h b/third_party/WebKit/Source/platform/scheduler/base/work_queue.h |
| index 36e6fb72b4cf1693a696e2b5a53cb1dcfb3ffde3..5c726929d5a3c941efe71c5a5efcdb53fdb30b6a 100644 |
| --- a/third_party/WebKit/Source/platform/scheduler/base/work_queue.h |
| +++ b/third_party/WebKit/Source/platform/scheduler/base/work_queue.h |
| @@ -22,6 +22,12 @@ class WorkQueueSets; |
| // This class keeps track of immediate and delayed tasks which are due to run |
| // now. It interfaces deeply with WorkQueueSets which keeps track of which queue |
| // (with a given priority) contains the oldest task. |
| +// |
| +// If a fence is inserted, WorkQueue behaves normally up until |
| +// TakeTaskFromWorkQueue reaches or exceeds the fence. At that point it the |
| +// API subset used by WorkQueueSets pretends the WorkQueue is empty until the |
| +// fence is removed. This functionality is a primitive intended for use by |
| +// throttling mechanisms. |
| class BLINK_PLATFORM_EXPORT WorkQueue { |
| public: |
| WorkQueue(TaskQueueImpl* task_queue, |
| @@ -38,22 +44,24 @@ class BLINK_PLATFORM_EXPORT WorkQueue { |
| void AsValueInto(base::trace_event::TracedValue* state) const; |
| - // Clears the |work_queue_|. |
| - void Clear(); |
| - |
| - // returns true if the |work_queue_| is empty. |
| + // Returns true if the |work_queue_| is empty. This method ignores any fences. |
| bool Empty() const { return work_queue_.empty(); } |
| - // If the |work_queue_| isn't empty, |enqueue_order| gets set to the enqueue |
| - // order of the front task and the function returns true. Otherwise the |
| - // function returns false. |
| + // If the |work_queue_| isn't empty and a fence hasn't been reached, |
| + // |enqueue_order| gets set to the enqueue order of the front task and the |
| + // function returns true. Otherwise the function returns false. |
| bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; |
| - // Returns the first task in this queue or null if the queue is empty. |
| + // Returns the first task in this queue or null if the queue is empty. This |
| + // method ignores any fences. |
| const TaskQueueImpl::Task* GetFrontTask() const; |
| - // Pushes the task onto the |work_queue_| and informs the WorkQueueSets if |
| - // the head changed. |
| + // Returns the first task in this queue or null if the queue is empty. This |
| + // method ignores any fences. |
| + const TaskQueueImpl::Task* GetBackTask() const; |
| + |
| + // Pushes the task onto the |work_queue_| and a fence hasn't been reached it |
| + // informs the WorkQueueSets if the head changed. |
| void Push(TaskQueueImpl::Task task); |
| // Removes a cancelled task from the |work_queue_|. Note |key| isn't required |
| @@ -66,14 +74,16 @@ class BLINK_PLATFORM_EXPORT WorkQueue { |
| // constructed by TaskQueueImpl::Task::CreateFakeTaskFromHandle. |
| bool IsTaskPending(const TaskQueueImpl::Task& key) const; |
| - // Swap the |work_queue_| with |incoming_queue| and informs the |
| - // WorkQueueSets if the head changed. Assumes |task_queue_->any_thread_lock_| |
| - // is locked. |
| + // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been |
| + // reached it informs the WorkQueueSets if the head changed. Assumes |
| + // |task_queue_->any_thread_lock_| is locked. |
| void SwapLocked(TaskQueueImpl::ComparatorQueue& incoming_queue); |
| size_t Size() const { return work_queue_.size(); } |
| - // Pulls a task off the |work_queue_| and informs the WorkQueueSets. |
| + // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the |
| + // task removed had an enqueue order >= the current fence than WorkQueue |
|
Sami
2016/08/26 14:37:02
s/than/then/
Sami
2016/08/26 16:44:01
Missed this?
alex clarke (OOO till 29th)
2016/08/26 16:47:38
Oops done.
|
| + // pretends to be empty as far as the WorkQueueSets is concrned. |
| TaskQueueImpl::Task TakeTaskFromWorkQueue(); |
| const char* name() const { return name_; } |
| @@ -89,15 +99,32 @@ class BLINK_PLATFORM_EXPORT WorkQueue { |
| // Returns true if the front task in this queue has an older enqueue order |
| // than the front task of |other_queue|. Both queue are assumed to be |
| - // non-empty. |
| + // non-empty. This method ignores any fences. |
| bool ShouldRunBefore(const WorkQueue* other_queue) const; |
| + // If |fence| is zero then WorkQueue will immediately start pretending to be |
| + // empty, and returns false. |
|
Sami
2016/08/26 14:37:03
"and this function returns false"?
alex clarke (OOO till 29th)
2016/08/26 16:33:14
Done.
|
| + // If |fence| is non-zero then when TakeTaskFromWorkQueue returns a task whose |
| + // enqueue_order is >= |fence| WorkQueue will start pretending to be empty. |
| + // Returns true if |fence| unblocked some previously blocked tasks, returns |
| + // false otherwise. |
| + bool InsertFence(EnqueueOrder fence); |
|
Sami
2016/08/26 14:37:03
The API here feels slightly magical. I wonder if w
alex clarke (OOO till 29th)
2016/08/26 16:33:14
Done.
|
| + |
| + // Removes any fences that where added and if WorkQueue was pretending to be |
| + // empty, then the real value is reported to WorkQueueSets. Returns true if |
| + // any tasks where unblocked. |
| + bool RemoveFence(); |
| + |
| + bool fence_hit() const { return fence_hit_; } |
| + |
| private: |
| TaskQueueImpl::ComparatorQueue work_queue_; |
| WorkQueueSets* work_queue_sets_; // NOT OWNED. |
| TaskQueueImpl* task_queue_; // NOT OWNED. |
| size_t work_queue_set_index_; |
| const char* name_; |
| + EnqueueOrder fence_; |
| + bool fence_hit_; |
| DISALLOW_COPY_AND_ASSIGN(WorkQueue); |
| }; |