| 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..ae1f21415f09e46bf87a70509ee2a4a31ccb1320 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 then WorkQueue
|
| + // pretends to be empty as far as the WorkQueueSets is concrned.
|
| TaskQueueImpl::Task TakeTaskFromWorkQueue();
|
|
|
| const char* name() const { return name_; }
|
| @@ -89,15 +99,33 @@ 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;
|
|
|
| + // Submit a fence. When TakeTaskFromWorkQueue encounters a task whose
|
| + // enqueue_order is >= |fence| then the WorkQueue will start pretending to be.
|
| + // empty.
|
| + // Inserting a fence may supersede a previous one and unblock some tasks.
|
| + // Returns true if any tasks where unblocked, returns false otherwise.
|
| + bool InsertFence(EnqueueOrder fence);
|
| +
|
| + // 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();
|
| +
|
| + // Returns true if any tasks are blocked by the fence. Returns true if the
|
| + // queue is empty and fence has been set (i.e. future tasks would be blocked).
|
| + // Otherwise returns false.
|
| + bool BlockedByFence() const;
|
| +
|
| 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_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WorkQueue);
|
| };
|
|
|