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

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

Issue 1895513002: TaskScheduler [12] Support SINGLE_THREADED in SchedulerThreadPool DO NOT SUBMIT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@10_superstack
Patch Set: rebase 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_SCHEDULER_WORKER_THREAD_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/atomicops.h"
10 #include "base/base_export.h" 11 #include "base/base_export.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "base/task_scheduler/priority_queue.h" 16 #include "base/task_scheduler/priority_queue.h"
16 #include "base/task_scheduler/scheduler_lock.h" 17 #include "base/task_scheduler/scheduler_lock.h"
17 #include "base/task_scheduler/scheduler_task_executor.h" 18 #include "base/task_scheduler/scheduler_task_executor.h"
18 #include "base/task_scheduler/sequence.h" 19 #include "base/task_scheduler/sequence.h"
19 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // Destroying a SchedulerWorkerThread in production is not allowed; it is 77 // Destroying a SchedulerWorkerThread in production is not allowed; it is
77 // always leaked. In tests, it can only be destroyed after JoinForTesting() 78 // always leaked. In tests, it can only be destroyed after JoinForTesting()
78 // has returned. 79 // has returned.
79 ~SchedulerWorkerThread() override; 80 ~SchedulerWorkerThread() override;
80 81
81 // Returns a SingleThreadTaskRunner whose PostTask invocations will result in 82 // Returns a SingleThreadTaskRunner whose PostTask invocations will result in
82 // scheduling Tasks with |traits| on this worker thread. 83 // scheduling Tasks with |traits| on this worker thread.
83 scoped_refptr<SingleThreadTaskRunner> CreateTaskRunnerWithTraits( 84 scoped_refptr<SingleThreadTaskRunner> CreateTaskRunnerWithTraits(
84 const TaskTraits& traits); 85 const TaskTraits& traits);
85 86
87 // Returns the number of single-thread TaskRunners associated with this
88 // SchedulerWorkerThread.
89 size_t GetNumSingleThreadTaskRunners() const;
90
86 // Wakes up this SchedulerWorkerThread if it wasn't already awake. After this 91 // Wakes up this SchedulerWorkerThread if it wasn't already awake. After this
87 // is called, this SchedulerWorkerThread will run Tasks from Sequences 92 // is called, this SchedulerWorkerThread will run Tasks from Sequences
88 // returned by the GetWork() method of its delegate until it returns nullptr. 93 // returned by the GetWork() method of its delegate until it returns nullptr.
89 void WakeUp(); 94 void WakeUp();
90 95
91 // Joins this SchedulerWorkerThread. If a Task is already running, it will be 96 // Joins this SchedulerWorkerThread. If a Task is already running, it will be
92 // allowed to complete its execution. This can only be called once. 97 // allowed to complete its execution. This can only be called once.
93 void JoinForTesting(); 98 void JoinForTesting();
94 99
95 // SchedulerTaskExecutor: 100 // SchedulerTaskExecutor:
(...skipping 11 matching lines...) Expand all
107 void ThreadMain() override; 112 void ThreadMain() override;
108 113
109 bool ShouldExitForTesting() const; 114 bool ShouldExitForTesting() const;
110 115
111 // Platform thread managed by this SchedulerWorkerThread. 116 // Platform thread managed by this SchedulerWorkerThread.
112 PlatformThreadHandle thread_handle_; 117 PlatformThreadHandle thread_handle_;
113 118
114 // Event signaled to wake up this SchedulerWorkerThread. 119 // Event signaled to wake up this SchedulerWorkerThread.
115 WaitableEvent wake_up_event_; 120 WaitableEvent wake_up_event_;
116 121
122 // Number of single-thread TaskRunners associated with this
123 // SchedulerWorkerThread.
124 base::subtle::Atomic32 num_single_thread_task_runners_;
125
117 // PriorityQueue for Tasks/Sequences posted through SingleThreadTaskRunners 126 // PriorityQueue for Tasks/Sequences posted through SingleThreadTaskRunners
118 // returned by CreateTaskRunnerWithTraits. 127 // returned by CreateTaskRunnerWithTraits.
119 PriorityQueue single_threaded_priority_queue_; 128 PriorityQueue single_threaded_priority_queue_;
120 129
121 Delegate* const delegate_; 130 Delegate* const delegate_;
122 TaskTracker* const task_tracker_; 131 TaskTracker* const task_tracker_;
123 DelayedTaskManager* const delayed_task_manager_; 132 DelayedTaskManager* const delayed_task_manager_;
124 133
125 // Synchronizes access to |should_exit_for_testing_|. 134 // Synchronizes access to |should_exit_for_testing_|.
126 mutable SchedulerLock should_exit_for_testing_lock_; 135 mutable SchedulerLock should_exit_for_testing_lock_;
127 136
128 // True once JoinForTesting() has been called. 137 // True once JoinForTesting() has been called.
129 bool should_exit_for_testing_ = false; 138 bool should_exit_for_testing_ = false;
130 139
131 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThread); 140 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThread);
132 }; 141 };
133 142
134 } // namespace internal 143 } // namespace internal
135 } // namespace base 144 } // namespace base
136 145
137 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_ 146 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool_unittest.cc ('k') | base/task_scheduler/scheduler_worker_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698