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

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

Issue 2845913004: Remove TaskScheduler::CreateAndSetDefaultTaskScheduler(). (Closed)
Patch Set: fix-build-error Created 3 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
« no previous file with comments | « base/task_scheduler/task_scheduler.cc ('k') | base/test/scoped_task_environment.cc » ('j') | 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/task_scheduler/scheduler_worker_pool_params.h" 8 #include "base/task_scheduler/scheduler_worker_pool_params.h"
9 #include "base/task_scheduler/task_scheduler.h" 9 #include "base/task_scheduler/task_scheduler.h"
10 10
11 namespace base { 11 namespace base {
12 namespace test { 12 namespace test {
13 13
14 ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() { 14 ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() {
15 DCHECK(!TaskScheduler::GetInstance()); 15 DCHECK(!TaskScheduler::GetInstance());
16 16
17 // Instantiate a TaskScheduler with 1 thread in each of its 4 pools. Threads 17 // Instantiate a TaskScheduler with 1 thread in each of its 4 pools. Threads
18 // stay alive even when they don't have work. 18 // stay alive even when they don't have work.
19 constexpr int kMaxThreads = 1; 19 constexpr int kMaxThreads = 1;
20 const TimeDelta kSuggestedReclaimTime = TimeDelta::Max(); 20 const TimeDelta kSuggestedReclaimTime = TimeDelta::Max();
21 const SchedulerWorkerPoolParams worker_pool_params( 21 const SchedulerWorkerPoolParams worker_pool_params(
22 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads, 22 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads,
23 kSuggestedReclaimTime); 23 kSuggestedReclaimTime);
24 TaskScheduler::CreateAndSetDefaultTaskScheduler( 24 TaskScheduler::Create("ScopedAsync");
25 "ScopedAsync", {worker_pool_params, worker_pool_params,
26 worker_pool_params, worker_pool_params});
27 task_scheduler_ = TaskScheduler::GetInstance(); 25 task_scheduler_ = TaskScheduler::GetInstance();
26 TaskScheduler::GetInstance()->Start({worker_pool_params, worker_pool_params,
27 worker_pool_params, worker_pool_params});
28 } 28 }
29 29
30 ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() { 30 ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() {
31 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); 31 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
32 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be 32 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be
33 // skipped, resulting in memory leaks. 33 // skipped, resulting in memory leaks.
34 TaskScheduler::GetInstance()->FlushForTesting(); 34 TaskScheduler::GetInstance()->FlushForTesting();
35 TaskScheduler::GetInstance()->Shutdown(); 35 TaskScheduler::GetInstance()->Shutdown();
36 TaskScheduler::GetInstance()->JoinForTesting(); 36 TaskScheduler::GetInstance()->JoinForTesting();
37 TaskScheduler::SetInstance(nullptr); 37 TaskScheduler::SetInstance(nullptr);
38 } 38 }
39 39
40 } // namespace test 40 } // namespace test
41 } // namespace base 41 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler.cc ('k') | base/test/scoped_task_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698