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

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

Issue 1701343003: TaskScheduler [13] TaskSchedulerImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_6_threadpool
Patch Set: fix ios build error Created 4 years, 7 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
« no previous file with comments | « base/task_scheduler/task_scheduler.cc ('k') | base/task_scheduler/task_scheduler_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
7
8 #include <memory>
9
10 #include "base/base_export.h"
11 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/waitable_event.h"
15 #include "base/task_runner.h"
16 #include "base/task_scheduler/delayed_task_manager.h"
17 #include "base/task_scheduler/scheduler_thread_pool_impl.h"
18 #include "base/task_scheduler/sequence.h"
19 #include "base/task_scheduler/task_scheduler.h"
20 #include "base/task_scheduler/task_tracker.h"
21 #include "base/task_scheduler/task_traits.h"
22
23 namespace base {
24 namespace internal {
25
26 // Default TaskScheduler implementation. This class is thread-safe.
27 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
28 public:
29 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to
30 // do so (never returns null).
31 static std::unique_ptr<TaskSchedulerImpl> Create();
32
33 // Destroying a TaskSchedulerImpl is not allowed in production; it is always
34 // leaked. In tests, it can only be destroyed after JoinForTesting() has
35 // returned.
36 ~TaskSchedulerImpl() override;
37
38 // TaskScheduler:
39 void PostTaskWithTraits(const tracked_objects::Location& from_here,
40 const TaskTraits& traits,
41 const Closure& task) override;
42 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
43 const TaskTraits& traits,
44 ExecutionMode execution_mode) override;
45 void Shutdown() override;
46
47 // Joins all threads of this scheduler. Tasks that are already running are
48 // allowed to complete their execution. This can only be called once.
49 void JoinForTesting();
50
51 private:
52 TaskSchedulerImpl();
53
54 void Initialize();
55
56 // Returns the thread pool that runs Tasks with |traits|.
57 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits);
58
59 // Callback invoked when a non-single-thread |sequence| isn't empty after a
60 // worker thread pops a Task from it.
61 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence);
62
63 TaskTracker task_tracker_;
64 DelayedTaskManager delayed_task_manager_;
65
66 // Thread pool for BACKGROUND Tasks without file I/O.
67 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_;
68
69 // Thread pool for BACKGROUND Tasks with file I/O.
70 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_;
71
72 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O.
73 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_;
74
75 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O.
76 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_;
77
78 #if DCHECK_IS_ON()
79 // Signaled once JoinForTesting() has returned.
80 WaitableEvent join_for_testing_returned_;
81 #endif
82
83 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl);
84 };
85
86 } // namespace internal
87 } // namespace base
88
89 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler.cc ('k') | base/task_scheduler/task_scheduler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698