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

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: Try to fix test bug 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
24 class SCHEDULER_EXPORT TimeDomain : public base::RefCounted<TimeDomain> {
25 public:
26 TimeDomain();
27
28 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from
29 // any thread.
Sami 2015/11/19 14:52:23 Could you add a TODO for making this main thread o
alex clarke (OOO till 29th) 2015/11/19 15:57:14 Done.
30 virtual LazyNow CreateLazyNow() = 0;
31
32 // Some TimeDomains support virtual time, this method tells us to advance time
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 // Migrates |queue| from this time domain to |destination_time_domain|.
49 void MigrateQueue(internal::TaskQueueImpl* queue,
50 TimeDomain* destination_time_domain);
51
52 // If there is a scheduled delayed task, |out_time| is set to the scheduled
53 // runtime for the next one and it returns true. Returns false otherwise.
54 bool NextScheduledRunTime(base::TimeTicks* out_time) const;
55
56 // If there is a scheduled delayed task, |out_task_queue| is set to the queue
57 // the next task was posted to and it returns true. Returns false otherwise.
58 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const;
59
60 // Adds |queue| to the set of task queues that UpdateWorkQueues calls
61 // UpdateWorkQueue on.
62 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
63
64 // Schedules a call to TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue
65 // when this TimeDomain reaches |delayed_run_time|.
66 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
67 base::TimeTicks delayed_run_time,
68 LazyNow* lazy_now);
69
70 // Removes |queue| from the set of task queues that UpdateWorkQueues calls
71 // UpdateWorkQueue on.
72 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
73
74 // Removes |queue| from all internal data structures.
75 void UnregisterQueue(internal::TaskQueueImpl* queue);
76
77 // Updates active queues associated with this TimeDomain.
78 void UpdateWorkQueues(bool should_trigger_wakeup,
79 const internal::TaskQueueImpl::Task* previous_task);
80
81 // The implementaion will secedule task processing to run with |delay| with
82 // respect to the TimeDomain's time source.
83 virtual void RequestWakeup(base::TimeDelta delay) = 0;
84
85 // For implementation specific tracing.
86 virtual void AsValueIntoInternal(
87 base::trace_event::TracedValue* state) const = 0;
88
89 // Call TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue for each
90 // queue where the delay has elapsed.
91 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
92
93 private:
94 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
95
96 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*>
97 DelayedWakeupMultimap;
98
99 DelayedWakeupMultimap delayed_wakeup_multimap_;
100
101 // This lock guards only |newly_updatable_|. It's not expected to be heavily
102 // contended.
103 base::Lock newly_updatable_lock_;
104 std::vector<internal::TaskQueueImpl*> newly_updatable_;
105
106 // Set of task queues with avaliable work on the incoming queue. This should
107 // only be accessed from the main thread.
108 std::set<internal::TaskQueueImpl*> updatable_queue_set_;
109
110 base::ThreadChecker main_thread_checker_;
111 base::WeakPtrFactory<TimeDomain> weak_factory_;
112
113 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
114 };
115
116 } // namespace scheduler
117
118 #endif // COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698