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

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: initial patch for review 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
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/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "base/task_runner.h"
15 #include "base/task_scheduler/delayed_task_manager.h"
16 #include "base/task_scheduler/scheduler_thread_pool_impl.h"
17 #include "base/task_scheduler/sequence.h"
18 #include "base/task_scheduler/task_scheduler.h"
19 #include "base/task_scheduler/task_tracker.h"
20 #include "base/task_scheduler/task_traits.h"
21
22 namespace base {
23 namespace internal {
24
25 // Default TaskScheduler implementation. This class is thread-safe.
26 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
27 public:
28 // Destroying a TaskSchedulerImpl is not allowed in production; it is always
29 // leaked. In tests, it can only be destroyed after JoinForTesting() has
30 // returned.
31 ~TaskSchedulerImpl() override;
32
33 static std::unique_ptr<TaskSchedulerImpl> Create();
gab 2016/04/27 19:15:28 // Creates and returns an initialized TaskSchedule
fdoray 2016/04/28 18:36:32 Removed this method. Added a similar comment on th
34
35 // TaskScheduler:
36 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
37 const TaskTraits& traits,
38 ExecutionMode execution_mode) override;
39 void Shutdown() override;
40
41 // Joins all threads of this scheduler. Tasks that are already running are
42 // allowed to complete their execution. This can only be called once.
43 void JoinForTesting();
44
45 private:
46 TaskSchedulerImpl();
47
48 void Initialize();
49
50 // Returns the thread pool that runs Tasks with |traits|.
51 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits);
52
53 // Callback invoked when a non-single-thread |sequence| isn't empty after a
54 // worker thread pops a Task from it.
55 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence);
56
57 TaskTracker task_tracker_;
58 DelayedTaskManager delayed_task_manager_;
59
60 // Thread pool for BACKGROUND Tasks without file I/O.
61 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_;
62
63 // Thread pool for BACKGROUND Tasks with file I/O.
64 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_;
65
66 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O.
67 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_;
68
69 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O.
70 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_;
71
72 // Signaled once JoinForTesting() has returned.
73 WaitableEvent join_for_testing_returned_;
gab 2016/04/27 19:15:28 #if DCHECK_IS_ON()
fdoray 2016/04/28 18:36:32 Done.
74
75 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl);
76 };
77
78 } // namespace internal
79 } // namespace base
80
81 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698