| 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_TIME_DOMAIN_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "platform/scheduler/base/lazy_now.h" | 16 #include "platform/scheduler/base/lazy_now.h" |
| 17 #include "platform/scheduler/base/task_queue_impl.h" | 17 #include "platform/scheduler/base/task_queue_impl.h" |
| 18 #include "wtf/FlatSet.h" |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 namespace scheduler { | 21 namespace scheduler { |
| 21 namespace internal { | 22 namespace internal { |
| 22 class TaskQueueImpl; | 23 class TaskQueueImpl; |
| 23 } // internal | 24 } // internal |
| 24 class TaskQueueManager; | 25 class TaskQueueManager; |
| 25 class TaskQueueManagerDelegate; | 26 class TaskQueueManagerDelegate; |
| 26 | 27 |
| 28 std::ostream& operator<<( |
| 29 std::ostream& os, |
| 30 const std::pair<base::TimeTicks, internal::TaskQueueImpl*>& pair); |
| 31 |
| 27 // The TimeDomain's job is to wake task queues up when their next delayed tasks | 32 // The TimeDomain's job is to wake task queues up when their next delayed tasks |
| 28 // are due to fire. TaskQueues request a wake up via ScheduleDelayedWork, when | 33 // are due to fire. TaskQueues request a wake up via ScheduleDelayedWork, when |
| 29 // the wake up is due the TimeDomain calls TaskQueue::WakeUpForDelayedWork. | 34 // the wake up is due the TimeDomain calls TaskQueue::WakeUpForDelayedWork. |
| 30 // The TimeDomain communicates with the TaskQueueManager to actually schedule | 35 // The TimeDomain communicates with the TaskQueueManager to actually schedule |
| 31 // the wake-ups on the underlying base::MessageLoop. Various levels of de-duping | 36 // the wake-ups on the underlying base::MessageLoop. Various levels of de-duping |
| 32 // are employed to prevent unnecessary posting of TaskQueueManager::DoWork. | 37 // are employed to prevent unnecessary posting of TaskQueueManager::DoWork. |
| 33 // | 38 // |
| 34 // Note the TimeDomain only knows about the first wakeup per queue, it's the | 39 // Note the TimeDomain only knows about the first wakeup per queue, it's the |
| 35 // responsibility of TaskQueueImpl to keep the time domain up to date if this | 40 // responsibility of TaskQueueImpl to keep the time domain up to date if this |
| 36 // changes. | 41 // changes. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 virtual void AsValueIntoInternal( | 132 virtual void AsValueIntoInternal( |
| 128 base::trace_event::TracedValue* state) const = 0; | 133 base::trace_event::TracedValue* state) const = 0; |
| 129 | 134 |
| 130 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay | 135 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay |
| 131 // has elapsed. | 136 // has elapsed. |
| 132 void WakeupReadyDelayedQueues(LazyNow* lazy_now); | 137 void WakeupReadyDelayedQueues(LazyNow* lazy_now); |
| 133 | 138 |
| 134 private: | 139 private: |
| 135 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); | 140 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); |
| 136 | 141 |
| 137 using DelayedWakeupMultimap = | 142 using DelayedWakeupSet = |
| 138 std::multimap<base::TimeTicks, internal::TaskQueueImpl*>; | 143 WTF::FlatSet<std::pair<base::TimeTicks, internal::TaskQueueImpl*>>; |
| 139 | 144 |
| 140 DelayedWakeupMultimap delayed_wakeup_multimap_; | 145 DelayedWakeupSet delayed_wakeup_set_; |
| 141 | |
| 142 // This map makes it easy to remove a queue from |delayed_wakeup_multimap_|. | |
| 143 // NOTE inserting or removing elements from a std::map does not invalidate any | |
| 144 // iterators. | |
| 145 using QueueToDelayedWakeupMultimapIteratorMap = | |
| 146 std::unordered_map<internal::TaskQueueImpl*, | |
| 147 DelayedWakeupMultimap::iterator>; | |
| 148 | |
| 149 QueueToDelayedWakeupMultimapIteratorMap | |
| 150 queue_to_delayed_wakeup_multimap_iterator_map_; | |
| 151 | 146 |
| 152 // This lock guards only |newly_updatable_|. It's not expected to be heavily | 147 // This lock guards only |newly_updatable_|. It's not expected to be heavily |
| 153 // contended. | 148 // contended. |
| 154 base::Lock newly_updatable_lock_; | 149 base::Lock newly_updatable_lock_; |
| 155 std::vector<internal::TaskQueueImpl*> newly_updatable_; | 150 std::vector<internal::TaskQueueImpl*> newly_updatable_; |
| 156 | 151 |
| 157 // Set of task queues with avaliable work on the incoming queue. This should | 152 // Set of task queues with avaliable work on the incoming queue. This should |
| 158 // only be accessed from the main thread. | 153 // only be accessed from the main thread. |
| 159 std::set<internal::TaskQueueImpl*> updatable_queue_set_; | 154 std::set<internal::TaskQueueImpl*> updatable_queue_set_; |
| 160 | 155 |
| 156 std::set<internal::TaskQueueImpl*> queues_; |
| 157 |
| 161 Observer* observer_; // NOT OWNED. | 158 Observer* observer_; // NOT OWNED. |
| 162 | 159 |
| 163 base::ThreadChecker main_thread_checker_; | 160 base::ThreadChecker main_thread_checker_; |
| 164 | 161 |
| 165 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | 162 DISALLOW_COPY_AND_ASSIGN(TimeDomain); |
| 166 }; | 163 }; |
| 167 | 164 |
| 168 } // namespace scheduler | 165 } // namespace scheduler |
| 169 } // namespace blink | 166 } // namespace blink |
| 170 | 167 |
| 171 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 168 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| OLD | NEW |