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

Side by Side Diff: base/task_scheduler/delayed_task_manager.h

Issue 1876363004: TaskScheduler [11] Support ExecutionMode::SINGLE_THREADED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@8_delayed
Patch Set: all post tasks go through SchedulerThreadPool Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ 5 #ifndef BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_
6 #define BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ 6 #define BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <queue> 11 #include <queue>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/task_scheduler/scheduler_lock.h" 18 #include "base/task_scheduler/scheduler_lock.h"
19 #include "base/task_scheduler/sequence.h" 19 #include "base/task_scheduler/sequence.h"
20 #include "base/task_scheduler/task.h" 20 #include "base/task_scheduler/task.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 22
23 namespace base { 23 namespace base {
24 namespace internal { 24 namespace internal {
25 25
26 class SchedulerThreadPoolInterface; 26 class SchedulerThreadPoolInterface;
27 class SchedulerWorkerThread;
27 28
28 // A DelayedTaskManager holds delayed Tasks until they become ripe for 29 // A DelayedTaskManager holds delayed Tasks until they become ripe for
29 // execution. When they become ripe for execution, it posts them to their 30 // execution. When they become ripe for execution, it posts them to their
30 // associated Sequence and SchedulerThreadPoolInterface. This class is thread- 31 // SchedulerThreadPoolInterface. This class is thread-safe.
31 // safe.
32 class BASE_EXPORT DelayedTaskManager { 32 class BASE_EXPORT DelayedTaskManager {
33 public: 33 public:
34 // |on_delayed_run_time_updated| is invoked when the delayed run time is 34 // |on_delayed_run_time_updated| is invoked when the delayed run time is
35 // updated as a result of adding a delayed task to the manager. 35 // updated as a result of adding a delayed task to the manager.
36 explicit DelayedTaskManager(const Closure& on_delayed_run_time_updated); 36 explicit DelayedTaskManager(const Closure& on_delayed_run_time_updated);
37 ~DelayedTaskManager(); 37 ~DelayedTaskManager();
38 38
39 // Adds |task| to a queue of delayed tasks. The task will be posted to 39 // Adds |task| to a queue of delayed tasks. The task will be posted to
40 // |thread_pool| as part of |sequence| the first time that PostReadyTasks() is 40 // |thread_pool| with |sequence| and |worker_thread| the first time that
41 // called while Now() is passed |task->delayed_run_time|. 41 // PostReadyTasks() is called while Now() is passed |task->delayed_run_time|.
42 // |worker_thread| is optional.
42 // 43 //
43 // TODO(robliao): Find a concrete way to manage |thread_pool|'s memory. It is 44 // TODO(robliao): Find a concrete way to manage the memory of |worker_thread|
44 // never deleted in production, but it is better not to spread this assumption 45 // and |thread_pool|. These objects are never deleted in production, but it is
45 // throughout the scheduler. 46 // better not to spread this assumption throughout the scheduler.
46 void AddDelayedTask(std::unique_ptr<Task> task, 47 void AddDelayedTask(std::unique_ptr<Task> task,
47 scoped_refptr<Sequence> sequence, 48 scoped_refptr<Sequence> sequence,
49 SchedulerWorkerThread* worker_thread,
48 SchedulerThreadPoolInterface* thread_pool); 50 SchedulerThreadPoolInterface* thread_pool);
49 51
50 // Posts delayed tasks that are ripe for execution. 52 // Posts delayed tasks that are ripe for execution.
51 // TODO(robliao): Call this from a service thread. 53 // TODO(robliao): Call this from a service thread.
52 void PostReadyTasks(); 54 void PostReadyTasks();
53 55
54 // Returns the next time at which a delayed task will become ripe for 56 // Returns the next time at which a delayed task will become ripe for
55 // execution, or a null TimeTicks if there are no pending delayed tasks. 57 // execution, or a null TimeTicks if there are no pending delayed tasks.
56 TimeTicks GetDelayedRunTime() const; 58 TimeTicks GetDelayedRunTime() const;
57 59
(...skipping 21 matching lines...) Expand all
79 // The index to assign to the next delayed task added to the manager. 81 // The index to assign to the next delayed task added to the manager.
80 uint64_t delayed_task_index_ = 0; 82 uint64_t delayed_task_index_ = 0;
81 83
82 DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager); 84 DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager);
83 }; 85 };
84 86
85 } // namespace internal 87 } // namespace internal
86 } // namespace base 88 } // namespace base
87 89
88 #endif // BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ 90 #endif // BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/delayed_task_manager.cc » ('j') | base/task_scheduler/scheduler_thread_pool.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698