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

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

Issue 2798563003: [scheduler] Add TaskQueue::Observer (Closed)
Patch Set: 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..bf0a23b8afb611bd00713078486314b239d27f45 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
@@ -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_wakeup() 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,8 @@ class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
bool BlockedByFence() const override;
const char* GetName() const override;
QueueType GetQueueType() const override;
+ void AddObserver(Observer* observer) override;
+ void RemoveObserver(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
@@ -249,11 +255,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 +269,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;
@@ -329,6 +338,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 TimeDomainScheduleDelayedWork(base::TimeTicks now);
+
+ void NotifyWakeupChangedOnMainThread(base::TimeTicks wakeup);
Sami 2017/04/04 19:07:30 nit: s/Wakeup/WakeUp/
altimin 2017/04/05 11:35:58 Done.
+
const base::PlatformThreadId thread_id_;
mutable base::Lock any_thread_lock_;

Powered by Google App Engine
This is Rietveld 408576698