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

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

Issue 2044023003: Virtualize The Existence of a Scheduler Worker Thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@detach
Patch Set: CR Feedback Created 4 years, 6 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_service_thread.h" 5 #include "base/task_scheduler/scheduler_service_thread.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // For delayed tasks with delays that are really close to each other, it is 46 // For delayed tasks with delays that are really close to each other, it is
47 // possible for the current time to advance beyond the required 47 // possible for the current time to advance beyond the required
48 // GetDelayedWaitTime. Return a minimum of TimeDelta() in the event that 48 // GetDelayedWaitTime. Return a minimum of TimeDelta() in the event that
49 // happens. 49 // happens.
50 TimeDelta sleep_time = next_time - delayed_task_manager_->Now(); 50 TimeDelta sleep_time = next_time - delayed_task_manager_->Now();
51 const TimeDelta zero_delta; 51 const TimeDelta zero_delta;
52 return sleep_time < zero_delta ? zero_delta : sleep_time; 52 return sleep_time < zero_delta ? zero_delta : sleep_time;
53 } 53 }
54 54
55 bool CanDetach(SchedulerWorkerThread* worker_thread) override {
56 return false;
57 }
58
55 private: 59 private:
56 DelayedTaskManager* const delayed_task_manager_; 60 DelayedTaskManager* const delayed_task_manager_;
57 61
58 DISALLOW_COPY_AND_ASSIGN(ServiceThreadDelegate); 62 DISALLOW_COPY_AND_ASSIGN(ServiceThreadDelegate);
59 }; 63 };
60 64
61 } // namespace 65 } // namespace
62 66
63 SchedulerServiceThread::~SchedulerServiceThread() = default; 67 SchedulerServiceThread::~SchedulerServiceThread() = default;
64 68
65 // static 69 // static
66 std::unique_ptr<SchedulerServiceThread> SchedulerServiceThread::Create( 70 std::unique_ptr<SchedulerServiceThread> SchedulerServiceThread::Create(
67 TaskTracker* task_tracker, DelayedTaskManager* delayed_task_manager) { 71 TaskTracker* task_tracker, DelayedTaskManager* delayed_task_manager) {
68 std::unique_ptr<SchedulerWorkerThread> worker_thread = 72 std::unique_ptr<SchedulerWorkerThread> worker_thread =
69 SchedulerWorkerThread::Create( 73 SchedulerWorkerThread::Create(
70 ThreadPriority::NORMAL, 74 ThreadPriority::NORMAL,
71 WrapUnique(new ServiceThreadDelegate(delayed_task_manager)), 75 WrapUnique(new ServiceThreadDelegate(delayed_task_manager)),
72 task_tracker); 76 task_tracker,
77 SchedulerWorkerThread::InitialWorkerState::ALIVE);
73 if (!worker_thread) 78 if (!worker_thread)
74 return nullptr; 79 return nullptr;
75 80
76 return WrapUnique(new SchedulerServiceThread(std::move(worker_thread))); 81 return WrapUnique(new SchedulerServiceThread(std::move(worker_thread)));
77 } 82 }
78 83
79 void SchedulerServiceThread::WakeUp() { 84 void SchedulerServiceThread::WakeUp() {
80 worker_thread_->WakeUp(); 85 worker_thread_->WakeUp();
81 } 86 }
82 87
83 void SchedulerServiceThread::JoinForTesting() { 88 void SchedulerServiceThread::JoinForTesting() {
84 worker_thread_->JoinForTesting(); 89 worker_thread_->JoinForTesting();
85 } 90 }
86 91
87 SchedulerServiceThread::SchedulerServiceThread( 92 SchedulerServiceThread::SchedulerServiceThread(
88 std::unique_ptr<SchedulerWorkerThread> worker_thread) 93 std::unique_ptr<SchedulerWorkerThread> worker_thread)
89 : worker_thread_(std::move(worker_thread)) {} 94 : worker_thread_(std::move(worker_thread)) {}
90 95
91 } // namespace internal 96 } // namespace internal
92 } // namespace base 97 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_thread_pool_impl.cc » ('j') | base/task_scheduler/scheduler_worker_thread.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698