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 |
| 9 namespace base { |
| 10 namespace test { |
| 11 |
| 12 ScopedTaskScheduler::ScopedTaskScheduler() { |
| 13 DCHECK(!TaskScheduler::GetInstance()); |
| 14 |
| 15 // Create a TaskScheduler with a single thread to make tests deterministic. |
| 16 constexpr int kMaxThreads = 1; |
| 17 TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads); |
| 18 task_scheduler_ = TaskScheduler::GetInstance(); |
| 19 } |
| 20 |
| 21 ScopedTaskScheduler::~ScopedTaskScheduler() { |
| 22 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); |
| 23 TaskScheduler::GetInstance()->Shutdown(); |
| 24 TaskScheduler::GetInstance()->JoinForTesting(); |
| 25 TaskScheduler::SetInstance(nullptr); |
| 26 } |
| 27 |
| 28 } // namespace test |
| 29 } // namespace base |
OLD | NEW |