OLD | NEW |
---|---|
(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 | |
OLD | NEW |