OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/task_scheduler/scheduler_worker_pool_impl.h" | 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 // Fast-forward time and post tasks that are ripe for execution. | 321 // Fast-forward time and post tasks that are ripe for execution. |
322 delayed_task_manager_.SetCurrentTime( | 322 delayed_task_manager_.SetCurrentTime( |
323 delayed_task_manager_.GetDelayedRunTime()); | 323 delayed_task_manager_.GetDelayedRunTime()); |
324 delayed_task_manager_.PostReadyTasks(); | 324 delayed_task_manager_.PostReadyTasks(); |
325 | 325 |
326 // The task should run. | 326 // The task should run. |
327 task_ran.Wait(); | 327 task_ran.Wait(); |
328 } | 328 } |
329 | 329 |
| 330 // Verify that the RunsTasksOnCurrentThread() method of a SEQUENCED TaskRunner |
| 331 // returns false when called from a task that isn't part of the sequence. |
| 332 TEST_P(TaskSchedulerWorkerPoolImplTest, SequencedRunsTasksOnCurrentThread) { |
| 333 scoped_refptr<TaskRunner> task_runner( |
| 334 worker_pool_->CreateTaskRunnerWithTraits(TaskTraits(), GetParam())); |
| 335 scoped_refptr<TaskRunner> sequenced_task_runner( |
| 336 worker_pool_->CreateTaskRunnerWithTraits(TaskTraits(), |
| 337 ExecutionMode::SEQUENCED)); |
| 338 |
| 339 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
| 340 WaitableEvent::InitialState::NOT_SIGNALED); |
| 341 task_runner->PostTask( |
| 342 FROM_HERE, |
| 343 Bind( |
| 344 [](scoped_refptr<TaskRunner> sequenced_task_runner, |
| 345 WaitableEvent* task_ran) { |
| 346 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); |
| 347 // Tests that use TestTaskFactory already verify that |
| 348 // RunsTasksOnCurrentThread() returns true when appropriate. |
| 349 task_ran->Signal(); |
| 350 }, |
| 351 sequenced_task_runner, Unretained(&task_ran))); |
| 352 task_ran.Wait(); |
| 353 } |
| 354 |
330 INSTANTIATE_TEST_CASE_P(Parallel, | 355 INSTANTIATE_TEST_CASE_P(Parallel, |
331 TaskSchedulerWorkerPoolImplTest, | 356 TaskSchedulerWorkerPoolImplTest, |
332 ::testing::Values(ExecutionMode::PARALLEL)); | 357 ::testing::Values(ExecutionMode::PARALLEL)); |
333 INSTANTIATE_TEST_CASE_P(Sequenced, | 358 INSTANTIATE_TEST_CASE_P(Sequenced, |
334 TaskSchedulerWorkerPoolImplTest, | 359 TaskSchedulerWorkerPoolImplTest, |
335 ::testing::Values(ExecutionMode::SEQUENCED)); | 360 ::testing::Values(ExecutionMode::SEQUENCED)); |
336 INSTANTIATE_TEST_CASE_P(SingleThreaded, | 361 INSTANTIATE_TEST_CASE_P(SingleThreaded, |
337 TaskSchedulerWorkerPoolImplTest, | 362 TaskSchedulerWorkerPoolImplTest, |
338 ::testing::Values(ExecutionMode::SINGLE_THREADED)); | 363 ::testing::Values(ExecutionMode::SINGLE_THREADED)); |
339 | 364 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 count_waiter->Wait(); | 573 count_waiter->Wait(); |
549 | 574 |
550 EXPECT_GT(subtle::NoBarrier_Load(&zero_tls_values_), 0); | 575 EXPECT_GT(subtle::NoBarrier_Load(&zero_tls_values_), 0); |
551 | 576 |
552 // Release tasks waiting on |waiter_|. | 577 // Release tasks waiting on |waiter_|. |
553 waiter_.Signal(); | 578 waiter_.Signal(); |
554 } | 579 } |
555 | 580 |
556 } // namespace internal | 581 } // namespace internal |
557 } // namespace base | 582 } // namespace base |
OLD | NEW |