| 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/intrusive_heap.h" | |
| 17 #include "platform/scheduler/base/lazy_now.h" | 16 #include "platform/scheduler/base/lazy_now.h" |
| 18 #include "platform/scheduler/base/task_queue_impl.h" | 17 #include "platform/scheduler/base/task_queue_impl.h" |
| 19 | 18 |
| 20 namespace blink { | 19 namespace blink { |
| 21 namespace scheduler { | 20 namespace scheduler { |
| 22 namespace internal { | 21 namespace internal { |
| 23 class TaskQueueImpl; | 22 class TaskQueueImpl; |
| 24 } // internal | 23 } // internal |
| 25 class TaskQueueManager; | 24 class TaskQueueManager; |
| 26 class TaskQueueManagerDelegate; | 25 class TaskQueueManagerDelegate; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 virtual void AsValueIntoInternal( | 127 virtual void AsValueIntoInternal( |
| 129 base::trace_event::TracedValue* state) const = 0; | 128 base::trace_event::TracedValue* state) const = 0; |
| 130 | 129 |
| 131 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay | 130 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay |
| 132 // has elapsed. | 131 // has elapsed. |
| 133 void WakeupReadyDelayedQueues(LazyNow* lazy_now); | 132 void WakeupReadyDelayedQueues(LazyNow* lazy_now); |
| 134 | 133 |
| 135 private: | 134 private: |
| 136 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); | 135 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); |
| 137 | 136 |
| 138 struct DelayedWakeup { | 137 using DelayedWakeupMultimap = |
| 139 base::TimeTicks time; | 138 std::multimap<base::TimeTicks, internal::TaskQueueImpl*>; |
| 140 internal::TaskQueueImpl* queue; | |
| 141 | 139 |
| 142 bool operator<=(const DelayedWakeup& other) const { | 140 DelayedWakeupMultimap delayed_wakeup_multimap_; |
| 143 if (time == other.time) | |
| 144 return queue < other.queue; | |
| 145 return time <= other.time; | |
| 146 } | |
| 147 | 141 |
| 148 void SetHeapHandle(HeapHandle handle) { queue->set_heap_handle(handle); } | 142 // This map makes it easy to remove a queue from |delayed_wakeup_multimap_|. |
| 149 }; | 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>; |
| 150 | 148 |
| 151 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_; | 149 QueueToDelayedWakeupMultimapIteratorMap |
| 150 queue_to_delayed_wakeup_multimap_iterator_map_; |
| 152 | 151 |
| 153 // This lock guards only |newly_updatable_|. It's not expected to be heavily | 152 // This lock guards only |newly_updatable_|. It's not expected to be heavily |
| 154 // contended. | 153 // contended. |
| 155 base::Lock newly_updatable_lock_; | 154 base::Lock newly_updatable_lock_; |
| 156 std::vector<internal::TaskQueueImpl*> newly_updatable_; | 155 std::vector<internal::TaskQueueImpl*> newly_updatable_; |
| 157 | 156 |
| 158 // Set of task queues with avaliable work on the incoming queue. This should | 157 // Set of task queues with avaliable work on the incoming queue. This should |
| 159 // only be accessed from the main thread. | 158 // only be accessed from the main thread. |
| 160 std::set<internal::TaskQueueImpl*> updatable_queue_set_; | 159 std::set<internal::TaskQueueImpl*> updatable_queue_set_; |
| 161 | 160 |
| 162 Observer* observer_; // NOT OWNED. | 161 Observer* observer_; // NOT OWNED. |
| 163 | 162 |
| 164 base::ThreadChecker main_thread_checker_; | 163 base::ThreadChecker main_thread_checker_; |
| 165 | 164 |
| 166 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | 165 DISALLOW_COPY_AND_ASSIGN(TimeDomain); |
| 167 }; | 166 }; |
| 168 | 167 |
| 169 } // namespace scheduler | 168 } // namespace scheduler |
| 170 } // namespace blink | 169 } // namespace blink |
| 171 | 170 |
| 172 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 171 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| OLD | NEW |