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

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h

Issue 2798563003: [scheduler] Add TaskQueue::Observer (Closed)
Patch Set: add todo for test timings & wake_up -> wake-up in comments Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h
diff --git a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h
index a50de1563f30f67241260e9d44d8430e1359fb42..e4297d792055175de6cae75118420e594a0c7faf 100644
--- a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h
+++ b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h
@@ -46,7 +46,7 @@ class WorkQueueSets;
// immediate_work_queue is swapped with immediate_incoming_queue when
// immediate_work_queue becomes empty.
//
-// Delayed tasks are initially posted to delayed_incoming_queue and a wakeup
+// Delayed tasks are initially posted to delayed_incoming_queue and a wake-up
// is scheduled with the TimeDomain. When the delay has elapsed, the TimeDomain
// calls UpdateDelayedWorkQueue and ready delayed tasks are moved into the
// delayed_work_queue. Note the EnqueueOrder (used for ordering) for a delayed
@@ -65,6 +65,21 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
const char* disabled_by_default_tracing_category,
const char* disabled_by_default_verbose_tracing_category);
+ // Represents a time at which a task wants to run. Tasks scheduled for the
+ // same point in time will be ordered by their sequence numbers.
+ struct DelayedWakeUp {
+ base::TimeTicks time;
+ int sequence_num;
+
+ bool operator<=(const DelayedWakeUp& other) const {
+ if (time == other.time) {
+ DCHECK_NE(sequence_num, other.sequence_num);
+ return (sequence_num - other.sequence_num) < 0;
+ }
+ return time < other.time;
+ }
+ };
+
class BLINK_PLATFORM_EXPORT Task : public base::PendingTask {
public:
Task();
@@ -81,6 +96,10 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
bool nestable,
EnqueueOrder enqueue_order);
+ DelayedWakeUp delayed_wake_up() const {
+ return DelayedWakeUp{delayed_run_time, sequence_num};
+ }
+
EnqueueOrder enqueue_order() const {
#ifndef NDEBUG
DCHECK(enqueue_order_set_);
@@ -112,21 +131,6 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
EnqueueOrder enqueue_order_;
};
- // Represents a time at which a task wants to run. Tasks scheduled for the
- // same point in time will be ordered by their sequence numbers.
- struct DelayedWakeUp {
- base::TimeTicks time;
- int sequence_num;
-
- bool operator<=(const DelayedWakeUp& other) const {
- if (time == other.time) {
- DCHECK_NE(sequence_num, other.sequence_num);
- return (sequence_num - other.sequence_num) < 0;
- }
- return time < other.time;
- }
- };
-
// TaskQueue implementation.
void UnregisterTaskQueue() override;
bool RunsTasksOnCurrentThread() const override;
@@ -155,6 +159,7 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
bool BlockedByFence() const override;
const char* GetName() const override;
QueueType GetQueueType() const override;
+ void SetObserver(Observer* observer) override;
// Returns true if a (potentially hypothetical) task with the specified
// |enqueue_order| could run on the queue. Must be called from the main
@@ -193,18 +198,18 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
}
// Enqueues any delayed tasks which should be run now on the
- // |delayed_work_queue|. Returns the subsequent wakeup that is required, if
+ // |delayed_work_queue|. Returns the subsequent wake-up that is required, if
// any. Must be called from the main thread.
base::Optional<DelayedWakeUp> WakeUpForDelayedWork(LazyNow* lazy_now);
- base::TimeTicks scheduled_time_domain_wakeup() const {
- return main_thread_only().scheduled_time_domain_wakeup;
+ base::TimeTicks scheduled_time_domain_wake_up() const {
+ return main_thread_only().scheduled_time_domain_wake_up;
}
- void set_scheduled_time_domain_wakeup(
- base::TimeTicks scheduled_time_domain_wakeup) {
- main_thread_only().scheduled_time_domain_wakeup =
- scheduled_time_domain_wakeup;
+ void set_scheduled_time_domain_wake_up(
+ base::TimeTicks scheduled_time_domain_wake_up) {
+ main_thread_only().scheduled_time_domain_wake_up =
+ scheduled_time_domain_wake_up;
}
HeapHandle heap_handle() const { return main_thread_only().heap_handle; }
@@ -249,11 +254,12 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
AnyThread(TaskQueueManager* task_queue_manager, TimeDomain* time_domain);
~AnyThread();
- // TaskQueueManager and TimeDomain are maintained in two copies:
+ // TaskQueueManager, TimeDomain and Observer are maintained in two copies:
// inside AnyThread and inside MainThreadOnly. They can be changed only from
// main thread, so it should be locked before accessing from other threads.
TaskQueueManager* task_queue_manager;
TimeDomain* time_domain;
+ Observer* observer;
};
struct MainThreadOnly {
@@ -262,10 +268,12 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
TimeDomain* time_domain);
~MainThreadOnly();
- // Another copy of TaskQueueManager and TimeDomain for lock-free access from
- // the main thread. See description inside struct AnyThread for details.
+ // Another copy of TaskQueueManager, TimeDomain and Observer
+ // for lock-free access from the main thread.
+ // See description inside struct AnyThread for details.
TaskQueueManager* task_queue_manager;
TimeDomain* time_domain;
+ Observer* observer;
std::unique_ptr<WorkQueue> delayed_work_queue;
std::unique_ptr<WorkQueue> immediate_work_queue;
@@ -277,7 +285,7 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
int voter_refcount;
base::trace_event::BlameContext* blame_context; // Not owned.
EnqueueOrder current_fence;
- base::TimeTicks scheduled_time_domain_wakeup;
+ base::TimeTicks scheduled_time_domain_wake_up;
};
~TaskQueueImpl() override;
@@ -329,6 +337,11 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
void OnQueueEnabledVoteChanged(bool enabled);
void EnableOrDisableWithSelector(bool enable);
+ // Schedules delayed work on time domain and calls the observer.
+ void ScheduleDelayedWorkInTimeDomain(base::TimeTicks now);
+
+ void NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up);
+
const base::PlatformThreadId thread_id_;
mutable base::Lock any_thread_lock_;

Powered by Google App Engine
This is Rietveld 408576698