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

Side by Side Diff: base/test/scoped_async_task_scheduler.cc

Issue 2795693006: Initialize TaskScheduler with InitParams in ScopedAsyncTaskScheduler. (Closed)
Patch Set: self-review Created 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/test/scoped_async_task_scheduler.h" 5 #include "base/test/scoped_async_task_scheduler.h"
6 6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/logging.h" 7 #include "base/logging.h"
11 #include "base/task_scheduler/scheduler_worker_pool_params.h" 8 #include "base/task_scheduler/scheduler_worker_pool_params.h"
12 #include "base/task_scheduler/task_scheduler.h" 9 #include "base/task_scheduler/task_scheduler.h"
13 #include "base/task_scheduler/task_scheduler_impl.h"
14 10
15 namespace base { 11 namespace base {
16 namespace test { 12 namespace test {
17 13
18 ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() { 14 ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() {
19 DCHECK(!TaskScheduler::GetInstance()); 15 DCHECK(!TaskScheduler::GetInstance());
16
17 // Instantiate a TaskScheduler with 1 thread in each of its 4 pools. Threads
18 // stay alive even when they don't have work.
20 constexpr int kMaxThreads = 1; 19 constexpr int kMaxThreads = 1;
21 const TimeDelta kSuggestedReclaimTime = TimeDelta::Max(); 20 const TimeDelta kSuggestedReclaimTime = TimeDelta::Max();
22 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector; 21 const SchedulerWorkerPoolParams worker_pool_params(
23 worker_pool_params_vector.emplace_back( 22 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads,
24 "ScopedAsyncTaskScheduler", ThreadPriority::NORMAL,
25 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, kMaxThreads,
26 kSuggestedReclaimTime); 23 kSuggestedReclaimTime);
27 TaskScheduler::CreateAndSetDefaultTaskScheduler( 24 TaskScheduler::CreateAndSetDefaultTaskScheduler(
28 worker_pool_params_vector, 25 "ScopedAsync", {worker_pool_params, worker_pool_params,
29 Bind([](const TaskTraits&) -> size_t { return 0; })); 26 worker_pool_params, worker_pool_params});
30 task_scheduler_ = TaskScheduler::GetInstance(); 27 task_scheduler_ = TaskScheduler::GetInstance();
31 } 28 }
32 29
33 ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() { 30 ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() {
34 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); 31 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
35 TaskScheduler::GetInstance()->Shutdown(); 32 TaskScheduler::GetInstance()->Shutdown();
36 static_cast<internal::TaskSchedulerImpl*>(TaskScheduler::GetInstance()) 33 TaskScheduler::GetInstance()->JoinForTesting();
37 ->JoinForTesting();
38 TaskScheduler::SetInstance(nullptr); 34 TaskScheduler::SetInstance(nullptr);
39 } 35 }
40 36
41 } // namespace test 37 } // namespace test
42 } // namespace base 38 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698