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

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

Issue 1903103007: TaskScheduler: Make SchedulerWorkerThread own its delegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2b_remove_utils
Patch Set: 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 #include "base/task_scheduler/scheduler_worker_thread.h" 5 #include "base/task_scheduler/scheduler_worker_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/task_scheduler/task_tracker.h" 12 #include "base/task_scheduler/task_tracker.h"
13 13
14 namespace base { 14 namespace base {
15 namespace internal { 15 namespace internal {
16 16
17 std::unique_ptr<SchedulerWorkerThread> 17 std::unique_ptr<SchedulerWorkerThread>
18 SchedulerWorkerThread::CreateSchedulerWorkerThread( 18 SchedulerWorkerThread::CreateWorkerThread(ThreadPriority thread_priority,
robliao 2016/04/22 20:30:48 While we're here, would Create(*) be sufficient as
fdoray 2016/04/22 22:46:46 Done. Also renamed SchedulerThreadPool::CreateThre
19 ThreadPriority thread_priority, 19 std::unique_ptr<Delegate> delegate,
20 Delegate* delegate, 20 TaskTracker* task_tracker) {
21 TaskTracker* task_tracker) {
22 std::unique_ptr<SchedulerWorkerThread> worker_thread( 21 std::unique_ptr<SchedulerWorkerThread> worker_thread(
23 new SchedulerWorkerThread(thread_priority, delegate, task_tracker)); 22 new SchedulerWorkerThread(thread_priority, std::move(delegate),
23 task_tracker));
24 24
25 if (worker_thread->thread_handle_.is_null()) 25 if (worker_thread->thread_handle_.is_null())
26 return nullptr; 26 return nullptr;
27 return worker_thread; 27 return worker_thread;
28 } 28 }
29 29
30 SchedulerWorkerThread::~SchedulerWorkerThread() { 30 SchedulerWorkerThread::~SchedulerWorkerThread() {
31 DCHECK(ShouldExitForTesting()); 31 DCHECK(ShouldExitForTesting());
32 } 32 }
33 33
34 void SchedulerWorkerThread::WakeUp() { 34 void SchedulerWorkerThread::WakeUp() {
35 wake_up_event_.Signal(); 35 wake_up_event_.Signal();
36 } 36 }
37 37
38 void SchedulerWorkerThread::JoinForTesting() { 38 void SchedulerWorkerThread::JoinForTesting() {
39 { 39 {
40 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); 40 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_);
41 should_exit_for_testing_ = true; 41 should_exit_for_testing_ = true;
42 } 42 }
43 WakeUp(); 43 WakeUp();
44 PlatformThread::Join(thread_handle_); 44 PlatformThread::Join(thread_handle_);
45 } 45 }
46 46
47 SchedulerWorkerThread::SchedulerWorkerThread(ThreadPriority thread_priority, 47 SchedulerWorkerThread::SchedulerWorkerThread(ThreadPriority thread_priority,
48 Delegate* delegate, 48 std::unique_ptr<Delegate> delegate,
49 TaskTracker* task_tracker) 49 TaskTracker* task_tracker)
50 : wake_up_event_(false, false), 50 : wake_up_event_(false, false),
51 delegate_(delegate), 51 delegate_(std::move(delegate)),
52 task_tracker_(task_tracker) { 52 task_tracker_(task_tracker) {
53 DCHECK(delegate_); 53 DCHECK(delegate_);
54 DCHECK(task_tracker_); 54 DCHECK(task_tracker_);
55 55
56 const size_t kDefaultStackSize = 0; 56 const size_t kDefaultStackSize = 0;
57 PlatformThread::CreateWithPriority(kDefaultStackSize, this, &thread_handle_, 57 PlatformThread::CreateWithPriority(kDefaultStackSize, this, &thread_handle_,
58 thread_priority); 58 thread_priority);
59 } 59 }
60 60
61 void SchedulerWorkerThread::ThreadMain() { 61 void SchedulerWorkerThread::ThreadMain() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 } 95 }
96 96
97 bool SchedulerWorkerThread::ShouldExitForTesting() const { 97 bool SchedulerWorkerThread::ShouldExitForTesting() const {
98 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); 98 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_);
99 return should_exit_for_testing_; 99 return should_exit_for_testing_;
100 } 100 }
101 101
102 } // namespace internal 102 } // namespace internal
103 } // namespace base 103 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698