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

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

Issue 2546423002: [Try # 3] Scheduler refactoring to virtually eliminate redundant DoWorks (Closed)
Patch Set: Add an extra dcheck Created 3 years, 11 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>
(...skipping 13 matching lines...) Expand all
24 // now. It interfaces deeply with WorkQueueSets which keeps track of which queue 24 // now. It interfaces deeply with WorkQueueSets which keeps track of which queue
25 // (with a given priority) contains the oldest task. 25 // (with a given priority) contains the oldest task.
26 // 26 //
27 // If a fence is inserted, WorkQueue behaves normally up until 27 // If a fence is inserted, WorkQueue behaves normally up until
28 // TakeTaskFromWorkQueue reaches or exceeds the fence. At that point it the 28 // TakeTaskFromWorkQueue reaches or exceeds the fence. At that point it the
29 // API subset used by WorkQueueSets pretends the WorkQueue is empty until the 29 // API subset used by WorkQueueSets pretends the WorkQueue is empty until the
30 // fence is removed. This functionality is a primitive intended for use by 30 // fence is removed. This functionality is a primitive intended for use by
31 // throttling mechanisms. 31 // throttling mechanisms.
32 class BLINK_PLATFORM_EXPORT WorkQueue { 32 class BLINK_PLATFORM_EXPORT WorkQueue {
33 public: 33 public:
34 WorkQueue(TaskQueueImpl* task_queue, const char* name); 34 enum class QueueType { DELAYED, IMMEDIATE };
35
36 WorkQueue(TaskQueueImpl* task_queue, const char* name, QueueType queue_type);
35 ~WorkQueue(); 37 ~WorkQueue();
36 38
37 // Associates this work queue with the given work queue sets. This must be 39 // Associates this work queue with the given work queue sets. This must be
38 // called before any tasks can be inserted into this work queue. 40 // called before any tasks can be inserted into this work queue.
39 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets); 41 void AssignToWorkQueueSets(WorkQueueSets* work_queue_sets);
40 42
41 // Assigns the current set index. 43 // Assigns the current set index.
42 void AssignSetIndex(size_t work_queue_set_index); 44 void AssignSetIndex(size_t work_queue_set_index);
43 45
44 void AsValueInto(base::trace_event::TracedValue* state) const; 46 void AsValueInto(base::trace_event::TracedValue* state) const;
(...skipping 11 matching lines...) Expand all
56 const TaskQueueImpl::Task* GetFrontTask() const; 58 const TaskQueueImpl::Task* GetFrontTask() const;
57 59
58 // Returns the last task in this queue or null if the queue is empty. This 60 // Returns the last task in this queue or null if the queue is empty. This
59 // method ignores any fences. 61 // method ignores any fences.
60 const TaskQueueImpl::Task* GetBackTask() const; 62 const TaskQueueImpl::Task* GetBackTask() const;
61 63
62 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it 64 // Pushes the task onto the |work_queue_| and a fence hasn't been reached it
63 // informs the WorkQueueSets if the head changed. 65 // informs the WorkQueueSets if the head changed.
64 void Push(TaskQueueImpl::Task task); 66 void Push(TaskQueueImpl::Task task);
65 67
66 // Swap the |work_queue_| with |incoming_queue| and if a fence hasn't been 68 // Reloads the empty |work_queue_| with
67 // reached it informs the WorkQueueSets if the head changed. Assumes 69 // |task_queue_->TakeImmediateIncomingQueue| and if a fence hasn't been
68 // |task_queue_->any_thread_lock_| is locked. 70 // reached it informs the WorkQueueSets if the head changed.
69 void SwapLocked(WTF::Deque<TaskQueueImpl::Task>& incoming_queue); 71 void ReloadEmptyImmediateQueue();
70 72
71 size_t Size() const { return work_queue_.size(); } 73 size_t Size() const { return work_queue_.size(); }
72 74
73 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the 75 // Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the
74 // task removed had an enqueue order >= the current fence then WorkQueue 76 // task removed had an enqueue order >= the current fence then WorkQueue
75 // pretends to be empty as far as the WorkQueueSets is concrned. 77 // pretends to be empty as far as the WorkQueueSets is concrned.
76 TaskQueueImpl::Task TakeTaskFromWorkQueue(); 78 TaskQueueImpl::Task TakeTaskFromWorkQueue();
77 79
78 const char* name() const { return name_; } 80 const char* name() const { return name_; }
79 81
(...skipping 27 matching lines...) Expand all
107 // any tasks where unblocked. 109 // any tasks where unblocked.
108 bool RemoveFence(); 110 bool RemoveFence();
109 111
110 // Returns true if any tasks are blocked by the fence. Returns true if the 112 // Returns true if any tasks are blocked by the fence. Returns true if the
111 // queue is empty and fence has been set (i.e. future tasks would be blocked). 113 // queue is empty and fence has been set (i.e. future tasks would be blocked).
112 // Otherwise returns false. 114 // Otherwise returns false.
113 bool BlockedByFence() const; 115 bool BlockedByFence() const;
114 116
115 private: 117 private:
116 WTF::Deque<TaskQueueImpl::Task> work_queue_; 118 WTF::Deque<TaskQueueImpl::Task> work_queue_;
117 WorkQueueSets* work_queue_sets_; // NOT OWNED. 119 WorkQueueSets* work_queue_sets_; // NOT OWNED.
118 TaskQueueImpl* task_queue_; // NOT OWNED. 120 TaskQueueImpl* const task_queue_; // NOT OWNED.
119 size_t work_queue_set_index_; 121 size_t work_queue_set_index_;
120 HeapHandle heap_handle_; 122 HeapHandle heap_handle_;
121 const char* name_; 123 const char* const name_;
122 EnqueueOrder fence_; 124 EnqueueOrder fence_;
125 const QueueType queue_type_;
123 126
124 DISALLOW_COPY_AND_ASSIGN(WorkQueue); 127 DISALLOW_COPY_AND_ASSIGN(WorkQueue);
125 }; 128 };
126 129
127 } // namespace internal 130 } // namespace internal
128 } // namespace scheduler 131 } // namespace scheduler
129 } // namespace blink 132 } // namespace blink
130 133
131 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_ 134 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORK_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698