Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/work_queue.h

Issue 2276353002: Remove after wakeup logic and replace PumpTask with Fences (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "platform/scheduler/base/enqueue_order.h" 14 #include "platform/scheduler/base/enqueue_order.h"
15 #include "platform/scheduler/base/task_queue_impl.h" 15 #include "platform/scheduler/base/task_queue_impl.h"
16 16
17 namespace blink { 17 namespace blink {
18 namespace scheduler { 18 namespace scheduler {
19 namespace internal { 19 namespace internal {
20 class WorkQueueSets; 20 class WorkQueueSets;
21 21
22 // This class keeps track of immediate and delayed tasks which are due to run 22 // This class keeps track of immediate and delayed tasks which are due to run
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 //
26 // If a fence is inserted, WorkQueue behaves normally up until
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
29 // fence is removed. This functionality is a primitive intended for use by
30 // throttling mechanisms.
25 class BLINK_PLATFORM_EXPORT WorkQueue { 31 class BLINK_PLATFORM_EXPORT WorkQueue {
26 public: 32 public:
27 WorkQueue(TaskQueueImpl* task_queue, 33 WorkQueue(TaskQueueImpl* task_queue,
28 const char* name, 34 const char* name,
29 TaskQueueImpl::Task::ComparatorFn queue_comparator); 35 TaskQueueImpl::Task::ComparatorFn queue_comparator);
30 ~WorkQueue(); 36 ~WorkQueue();
31 37
32 // 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
33 // called before any tasks can be inserted into this work queue. 39 // called before any tasks can be inserted into this work queue.
34 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); 40 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets);
35 41
36 // Assigns the current set index. 42 // Assigns the current set index.
37 void AssignSetIndex(size_t work_queue_set_index); 43 void AssignSetIndex(size_t work_queue_set_index);
38 44
39 void AsValueInto(base::trace_event::TracedValue* state) const; 45 void AsValueInto(base::trace_event::TracedValue* state) const;
40 46
41 // Clears the |work_queue_|. 47 // Returns true if the |work_queue_| is empty. This method ignores any fences.
42 void Clear();
43
44 // returns true if the |work_queue_| is empty.
45 bool Empty() const { return work_queue_.empty(); } 48 bool Empty() const { return work_queue_.empty(); }
46 49
47 // If the |work_queue_| isn't empty, |enqueue_order| gets set to the enqueue 50 // If the |work_queue_| isn't empty and a fence hasn't been reached,
48 // order of the front task and the function returns true. Otherwise the 51 // |enqueue_order| gets set to the enqueue order of the front task and the
49 // function returns false. 52 // function returns true. Otherwise the function returns false.
50 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; 53 bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const;
51 54
52 // Returns the first task in this queue or null if the queue is empty. 55 // Returns the first task in this queue or null if the queue is empty. This
56 // method ignores any fences.
53 const TaskQueueImpl::Task* GetFrontTask() const; 57 const TaskQueueImpl::Task* GetFrontTask() const;
54 58
55 // Pushes the task onto the |work_queue_| and informs the WorkQueueSets if 59 // Returns the first task in this queue or null if the queue is empty. This
56 // the head changed. 60 // method ignores any fences.
61 const TaskQueueImpl::Task* GetBackTask() const;
62
63 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it
64 // informs the WorkQueueSets if the head changed.
57 void Push(TaskQueueImpl::Task task); 65 void Push(TaskQueueImpl::Task task);
58 66
59 // Removes a cancelled task from the |work_queue_|. Note |key| isn't required 67 // Removes a cancelled task from the |work_queue_|. Note |key| isn't required
60 // to be the original task posted, it can be a fake key constructed by 68 // to be the original task posted, it can be a fake key constructed by
61 // TaskQueueImpl::Task::CreateFakeTaskFromHandle. 69 // TaskQueueImpl::Task::CreateFakeTaskFromHandle.
62 bool CancelTask(const TaskQueueImpl::Task& key); 70 bool CancelTask(const TaskQueueImpl::Task& key);
63 71
64 // Returns true if |work_queue_| contains a task matching |key|. Note |key| 72 // Returns true if |work_queue_| contains a task matching |key|. Note |key|
65 // isn't required to be the original task posted, it can be a fake key 73 // isn't required to be the original task posted, it can be a fake key
66 // constructed by TaskQueueImpl::Task::CreateFakeTaskFromHandle. 74 // constructed by TaskQueueImpl::Task::CreateFakeTaskFromHandle.
67 bool IsTaskPending(const TaskQueueImpl::Task& key) const; 75 bool IsTaskPending(const TaskQueueImpl::Task& key) const;
68 76
69 // Swap the |work_queue_| with |incoming_queue| and informs the 77 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been
70 // WorkQueueSets if the head changed. Assumes |task_queue_->any_thread_lock_| 78 // reached it informs the WorkQueueSets if the head changed. Assumes
71 // is locked. 79 // |task_queue_->any_thread_lock_| is locked.
72 void SwapLocked(TaskQueueImpl::ComparatorQueue& incoming_queue); 80 void SwapLocked(TaskQueueImpl::ComparatorQueue& incoming_queue);
73 81
74 size_t Size() const { return work_queue_.size(); } 82 size_t Size() const { return work_queue_.size(); }
75 83
76 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. 84 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the
85 // 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.
86 // pretends to be empty as far as the WorkQueueSets is concrned.
77 TaskQueueImpl::Task TakeTaskFromWorkQueue(); 87 TaskQueueImpl::Task TakeTaskFromWorkQueue();
78 88
79 const char* name() const { return name_; } 89 const char* name() const { return name_; }
80 90
81 TaskQueueImpl* task_queue() const { return task_queue_; } 91 TaskQueueImpl* task_queue() const { return task_queue_; }
82 92
83 WorkQueueSets* work_queue_sets() const { return work_queue_sets_; } 93 WorkQueueSets* work_queue_sets() const { return work_queue_sets_; }
84 94
85 size_t work_queue_set_index() const { return work_queue_set_index_; } 95 size_t work_queue_set_index() const { return work_queue_set_index_; }
86 96
87 // Test support function. This should not be used in production code. 97 // Test support function. This should not be used in production code.
88 void PopTaskForTest(); 98 void PopTaskForTest();
89 99
90 // Returns true if the front task in this queue has an older enqueue order 100 // Returns true if the front task in this queue has an older enqueue order
91 // than the front task of |other_queue|. Both queue are assumed to be 101 // than the front task of |other_queue|. Both queue are assumed to be
92 // non-empty. 102 // non-empty. This method ignores any fences.
93 bool ShouldRunBefore(const WorkQueue* other_queue) const; 103 bool ShouldRunBefore(const WorkQueue* other_queue) const;
94 104
105 // If |fence| is zero then WorkQueue will immediately start pretending to be
106 // 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.
107 // If |fence| is non-zero then when TakeTaskFromWorkQueue returns a task whose
108 // enqueue_order is >= |fence| WorkQueue will start pretending to be empty.
109 // Returns true if |fence| unblocked some previously blocked tasks, returns
110 // false otherwise.
111 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.
112
113 // Removes any fences that where added and if WorkQueue was pretending to be
114 // empty, then the real value is reported to WorkQueueSets. Returns true if
115 // any tasks where unblocked.
116 bool RemoveFence();
117
118 bool fence_hit() const { return fence_hit_; }
119
95 private: 120 private:
96 TaskQueueImpl::ComparatorQueue work_queue_; 121 TaskQueueImpl::ComparatorQueue work_queue_;
97 WorkQueueSets* work_queue_sets_; // NOT OWNED. 122 WorkQueueSets* work_queue_sets_; // NOT OWNED.
98 TaskQueueImpl* task_queue_; // NOT OWNED. 123 TaskQueueImpl* task_queue_; // NOT OWNED.
99 size_t work_queue_set_index_; 124 size_t work_queue_set_index_;
100 const char* name_; 125 const char* name_;
126 EnqueueOrder fence_;
127 bool fence_hit_;
101 128
102 DISALLOW_COPY_AND_ASSIGN(WorkQueue); 129 DISALLOW_COPY_AND_ASSIGN(WorkQueue);
103 }; 130 };
104 131
105 } // namespace internal 132 } // namespace internal
106 } // namespace scheduler 133 } // namespace scheduler
107 } // namespace blink 134 } // namespace blink
108 135
109 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ 136 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698