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

Side by Side Diff: components/scheduler/base/time_domain.h

Issue 1432263002: (reland) Adds TimeDomains to the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing some more feedback. Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
6 #define COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
7
8 #include <map>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "components/scheduler/base/lazy_now.h"
15 #include "components/scheduler/base/task_queue_impl.h"
16 #include "components/scheduler/scheduler_export.h"
17
18 namespace scheduler {
19 namespace internal {
20 class TaskQueueImpl;
21 } // internal
22 class TaskQueueManager;
23 class TaskQueueManagerDelegate;
24
25 class SCHEDULER_EXPORT TimeDomain : public base::RefCounted<TimeDomain> {
26 public:
27 explicit TimeDomain(TaskQueueManagerDelegate* task_queue_manager_delegate);
28
29 // Returns a LazyNow that evaluate this TimeDomain's Now.
30 virtual LazyNow GetLazyNow() = 0;
Sami 2015/11/18 18:36:24 nit: "Create" since this is creating a new one fro
31
32 // Some TimeDomains support vitual time, this method tells us to advance time
Sami 2015/11/18 18:36:24 typo: virtual
alex clarke (OOO till 29th) 2015/11/19 12:20:12 Done.
33 // if possible and return true if time was advanced.
34 virtual bool MaybeAdvanceTime() = 0;
35
36 // Returns the name of this time domain for tracing.
37 virtual const char* GetName() const = 0;
38
39 protected:
40 friend class internal::TaskQueueImpl;
41 friend class TaskQueueManager;
42 friend class base::RefCounted<TimeDomain>;
43
44 virtual ~TimeDomain();
45
46 void AsValueInto(base::trace_event::TracedValue* state) const;
47
48 // If there is a scheduled delayed task, |out_time| is set to the scheduled
49 // runtime for the next one and it returns true. Returns false otherwise.
50 bool NextScheduledRunTime(base::TimeTicks* out_time) const;
51
52 // If there is a scheduled delayed task, |out_task_queue| is set to the queue
53 // the next task was posted to and it returns true. Returns false otherwise.
54 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const;
55
56 // Adds |queue| to the set of task queues that UpdateWorkQueues calls
57 // UpdateWorkQueue on.
58 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
59
60 // Schedules a call to MoveReadyDelayedTasksToIncomingQueue when this
Sami 2015/11/18 18:36:24 nit: might want to fully qualify this to make it c
alex clarke (OOO till 29th) 2015/11/19 12:20:12 Done.
61 // TimeDomain reaches |delayed_run_time|.
62 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
63 base::TimeTicks delayed_run_time,
64 LazyNow* lazy_now);
65
66 // Removes |queue| from the set of task queues that UpdateWorkQueues calls
67 // UpdateWorkQueue on.
68 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
69
70 // Removes |queue| from all internal data structures.
71 void UnregisterQueue(internal::TaskQueueImpl* queue);
72
73 // Updates active queues associated with this TimeDomain.
74 void UpdateWorkQueues(bool should_trigger_wakeup,
75 const internal::TaskQueueImpl::Task* previous_task);
76
77 TaskQueueManagerDelegate* task_queue_manager_delegate() const {
78 return task_queue_manager_delegate_;
79 }
80
81 // The implementaion must arrange for TaskQueueManager::DoWork to be run with
82 // |delay| with respect to the TimeDomain's time source.
83 virtual void ScheduleDoWork(base::TimeDelta delay) = 0;
Sami 2015/11/18 18:36:24 I wonder if we can simplify this part a bit: the c
alex clarke (OOO till 29th) 2015/11/19 12:20:12 It's looking like all the various forms of virtual
84
85 // For implementation specific tracing.
86 virtual void AsValueIntoInternal(
87 base::trace_event::TracedValue* state) const = 0;
88
89 private:
90 // Function calling ScheduleDelayedWork that's suitable for use in base::Bind.
91 void ScheduleDelayedWorkTask(scoped_refptr<internal::TaskQueueImpl> queue,
92 base::TimeTicks delayed_run_time);
93
94 // Call TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue for each
95 // queue where the delay has elapsed.
96 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
97
98 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
99
100 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*>
101 DelayedWakeupMultimap;
102
103 DelayedWakeupMultimap delayed_wakeup_multimap_;
104 TaskQueueManagerDelegate* task_queue_manager_delegate_; // NOT OWNED
Sami 2015/11/18 18:36:24 I wonder if we remove the dependency on TaskQueueM
alex clarke (OOO till 29th) 2015/11/19 12:20:12 Done.
105
106 // This lock guards only |newly_updatable_|. It's not expected to be heavily
107 // contended.
108 base::Lock newly_updatable_lock_;
109 std::vector<internal::TaskQueueImpl*> newly_updatable_;
110
111 // Set of task queues with avaliable work on the incoming queue. This should
112 // only be accessed from the main thread.
113 std::set<internal::TaskQueueImpl*> updatable_queue_set_;
114
115 base::ThreadChecker main_thread_checker_;
116 base::WeakPtrFactory<TimeDomain> weak_factory_;
117
118 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
119 };
120
121 } // namespace scheduler
122
123 #endif // COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698