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

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

Issue 2511473004: Create base::test::ScopedTaskScheduler. (Closed)
Patch Set: self-review Created 4 years, 1 month 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/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/scoped_task_scheduler.h"
6
7 #include "base/task_scheduler/task_scheduler.h"
8 #include "base/time/time.h"
9
10 namespace base {
11 namespace test {
12
13 ScopedTaskScheduler::ScopedTaskScheduler() {
14 DCHECK(!TaskScheduler::GetInstance());
15
16 // Create a TaskScheduler with a single thread to make tests deterministic.
17 constexpr int kMaxThreads = 1;
18 const TimeDelta kDetachDuration = base::TimeDelta::Max();
gab 2016/11/17 14:39:35 FYI, TimeDelta can be constexpr too (but by commen
19 TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads, kDetachDuration);
20 task_scheduler_ = TaskScheduler::GetInstance();
21 }
22
23 ScopedTaskScheduler::~ScopedTaskScheduler() {
24 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance());
25 TaskScheduler::GetInstance()->Shutdown();
26 TaskScheduler::GetInstance()->JoinForTesting();
27 TaskScheduler::SetInstance(nullptr);
28 }
29
30 } // namespace test
31 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698