Chromium Code Reviews| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 // beginning of the test. | 712 // beginning of the test. |
| 713 EXPECT_EQ(static_cast<int>(kNumWorkersInWorkerPool), | 713 EXPECT_EQ(static_cast<int>(kNumWorkersInWorkerPool), |
| 714 histogram->SnapshotSamples()->GetCount(1)); | 714 histogram->SnapshotSamples()->GetCount(1)); |
| 715 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); | 715 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); |
| 716 | 716 |
| 717 tasks_can_exit_event.Signal(); | 717 tasks_can_exit_event.Signal(); |
| 718 worker_pool_->WaitForAllWorkersIdleForTesting(); | 718 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 719 worker_pool_->DisallowWorkerDetachmentForTesting(); | 719 worker_pool_->DisallowWorkerDetachmentForTesting(); |
| 720 } | 720 } |
| 721 | 721 |
| 722 // TODO(crbug.com/698046): disabled due to flakyness. | 722 // TODO(crbug.com/698046): disabled due to flakyness. |
|
gab
2017/03/15 19:23:11
rm comment
robliao
2017/03/15 20:05:55
Done in https://codereview.chromium.org/2750103004
| |
| 723 TEST_F(TaskSchedulerWorkerPoolHistogramTest, DISABLED_NumTasksBeforeDetach) { | 723 TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) { |
| 724 InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool); | 724 InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool); |
| 725 | 725 |
| 726 auto histogrammed_thread_task_runner = | 726 auto histogrammed_thread_task_runner = |
| 727 worker_pool_->CreateSequencedTaskRunnerWithTraits( | 727 worker_pool_->CreateSequencedTaskRunnerWithTraits( |
| 728 TaskTraits().WithBaseSyncPrimitives()); | 728 TaskTraits().WithBaseSyncPrimitives()); |
| 729 | 729 |
| 730 // Post 3 tasks and hold the thread for idle thread stack ordering. | 730 // Post 3 tasks and hold the thread for idle thread stack ordering. |
| 731 // This test assumes |histogrammed_thread_task_runner| gets assigned the same | 731 // This test assumes |histogrammed_thread_task_runner| gets assigned the same |
| 732 // thread for each of its tasks. | 732 // thread for each of its tasks. |
| 733 PlatformThreadRef thread_ref; | 733 PlatformThreadRef thread_ref; |
| 734 histogrammed_thread_task_runner->PostTask( | 734 histogrammed_thread_task_runner->PostTask( |
| 735 FROM_HERE, Bind( | 735 FROM_HERE, Bind( |
| 736 [](PlatformThreadRef* thread_ref) { | 736 [](PlatformThreadRef* thread_ref) { |
| 737 ASSERT_TRUE(thread_ref); | 737 ASSERT_TRUE(thread_ref); |
| 738 *thread_ref = PlatformThread::CurrentRef(); | 738 *thread_ref = PlatformThread::CurrentRef(); |
| 739 }, | 739 }, |
| 740 Unretained(&thread_ref))); | 740 Unretained(&thread_ref))); |
| 741 histogrammed_thread_task_runner->PostTask( | 741 histogrammed_thread_task_runner->PostTask( |
| 742 FROM_HERE, Bind( | 742 FROM_HERE, Bind( |
| 743 [](PlatformThreadRef thread_ref) { | 743 [](PlatformThreadRef* thread_ref) { |
| 744 EXPECT_EQ(thread_ref, PlatformThreadRef()); | 744 ASSERT_FALSE(thread_ref->is_null()); |
| 745 EXPECT_EQ(*thread_ref, PlatformThread::CurrentRef()); | |
| 745 }, | 746 }, |
| 746 thread_ref)); | 747 Unretained(&thread_ref))); |
| 748 | |
| 747 WaitableEvent detach_thread_running( | 749 WaitableEvent detach_thread_running( |
| 748 WaitableEvent::ResetPolicy::MANUAL, | 750 WaitableEvent::ResetPolicy::MANUAL, |
| 749 WaitableEvent::InitialState::NOT_SIGNALED); | 751 WaitableEvent::InitialState::NOT_SIGNALED); |
| 750 WaitableEvent detach_thread_continue( | 752 WaitableEvent detach_thread_continue( |
| 751 WaitableEvent::ResetPolicy::MANUAL, | 753 WaitableEvent::ResetPolicy::MANUAL, |
| 752 WaitableEvent::InitialState::NOT_SIGNALED); | 754 WaitableEvent::InitialState::NOT_SIGNALED); |
| 753 histogrammed_thread_task_runner->PostTask( | 755 histogrammed_thread_task_runner->PostTask( |
| 754 FROM_HERE, | 756 FROM_HERE, |
| 755 Bind( | 757 Bind( |
| 756 [](PlatformThreadRef thread_ref, WaitableEvent* detach_thread_running, | 758 [](PlatformThreadRef* thread_ref, |
| 759 WaitableEvent* detach_thread_running, | |
| 757 WaitableEvent* detach_thread_continue) { | 760 WaitableEvent* detach_thread_continue) { |
| 758 EXPECT_EQ(thread_ref, PlatformThreadRef()); | 761 ASSERT_FALSE(thread_ref->is_null()); |
| 762 EXPECT_EQ(*thread_ref, PlatformThread::CurrentRef()); | |
| 759 detach_thread_running->Signal(); | 763 detach_thread_running->Signal(); |
| 760 detach_thread_continue->Wait(); | 764 detach_thread_continue->Wait(); |
| 761 }, | 765 }, |
| 762 thread_ref, Unretained(&detach_thread_running), | 766 Unretained(&thread_ref), Unretained(&detach_thread_running), |
| 763 Unretained(&detach_thread_continue))); | 767 Unretained(&detach_thread_continue))); |
| 764 | 768 |
| 765 detach_thread_running.Wait(); | 769 detach_thread_running.Wait(); |
| 766 | 770 |
| 767 // To allow the SchedulerWorker associated with | 771 // To allow the SchedulerWorker associated with |
| 768 // |histogrammed_thread_task_runner| to detach, make sure it isn't on top of | 772 // |histogrammed_thread_task_runner| to detach, make sure it isn't on top of |
| 769 // the idle stack by waking up another SchedulerWorker via | 773 // the idle stack by waking up another SchedulerWorker via |
| 770 // |task_runner_for_top_idle|. |histogrammed_thread_task_runner| should | 774 // |task_runner_for_top_idle|. |histogrammed_thread_task_runner| should |
| 771 // release and go idle first and then |task_runner_for_top_idle| should | 775 // release and go idle first and then |task_runner_for_top_idle| should |
| 772 // release and go idle. This allows the SchedulerWorker associated with | 776 // release and go idle. This allows the SchedulerWorker associated with |
| 773 // |histogrammed_thread_task_runner| to detach. | 777 // |histogrammed_thread_task_runner| to detach. |
| 774 WaitableEvent top_idle_thread_running( | 778 WaitableEvent top_idle_thread_running( |
| 775 WaitableEvent::ResetPolicy::MANUAL, | 779 WaitableEvent::ResetPolicy::MANUAL, |
| 776 WaitableEvent::InitialState::NOT_SIGNALED); | 780 WaitableEvent::InitialState::NOT_SIGNALED); |
| 777 WaitableEvent top_idle_thread_continue( | 781 WaitableEvent top_idle_thread_continue( |
| 778 WaitableEvent::ResetPolicy::MANUAL, | 782 WaitableEvent::ResetPolicy::MANUAL, |
| 779 WaitableEvent::InitialState::NOT_SIGNALED); | 783 WaitableEvent::InitialState::NOT_SIGNALED); |
| 780 auto task_runner_for_top_idle = | 784 auto task_runner_for_top_idle = |
| 781 worker_pool_->CreateSequencedTaskRunnerWithTraits( | 785 worker_pool_->CreateSequencedTaskRunnerWithTraits( |
| 782 TaskTraits().WithBaseSyncPrimitives()); | 786 TaskTraits().WithBaseSyncPrimitives()); |
| 783 task_runner_for_top_idle->PostTask( | 787 task_runner_for_top_idle->PostTask( |
| 784 FROM_HERE, Bind( | 788 FROM_HERE, Bind( |
| 785 [](PlatformThreadRef thread_ref, | 789 [](PlatformThreadRef thread_ref, |
| 786 WaitableEvent* top_idle_thread_running, | 790 WaitableEvent* top_idle_thread_running, |
| 787 WaitableEvent* top_idle_thread_continue) { | 791 WaitableEvent* top_idle_thread_continue) { |
| 792 ASSERT_FALSE(thread_ref.is_null()); | |
| 788 EXPECT_NE(thread_ref, PlatformThread::CurrentRef()) | 793 EXPECT_NE(thread_ref, PlatformThread::CurrentRef()) |
| 789 << "Worker reused. Thread will not detach and the " | 794 << "Worker reused. Thread will not detach and the " |
| 790 "histogram value will be wrong."; | 795 "histogram value will be wrong."; |
| 791 top_idle_thread_running->Signal(); | 796 top_idle_thread_running->Signal(); |
| 792 top_idle_thread_continue->Wait(); | 797 top_idle_thread_continue->Wait(); |
| 793 }, | 798 }, |
| 794 thread_ref, Unretained(&top_idle_thread_running), | 799 thread_ref, Unretained(&top_idle_thread_running), |
| 795 Unretained(&top_idle_thread_continue))); | 800 Unretained(&top_idle_thread_continue))); |
| 796 top_idle_thread_running.Wait(); | 801 top_idle_thread_running.Wait(); |
| 797 detach_thread_continue.Signal(); | 802 detach_thread_continue.Signal(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 StandbyThreadPolicy::ONE, 8U, TimeDelta::Max()), | 856 StandbyThreadPolicy::ONE, 8U, TimeDelta::Max()), |
| 852 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, | 857 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, |
| 853 &delayed_task_manager); | 858 &delayed_task_manager); |
| 854 ASSERT_TRUE(worker_pool); | 859 ASSERT_TRUE(worker_pool); |
| 855 EXPECT_EQ(1U, worker_pool->NumberOfAliveWorkersForTesting()); | 860 EXPECT_EQ(1U, worker_pool->NumberOfAliveWorkersForTesting()); |
| 856 worker_pool->JoinForTesting(); | 861 worker_pool->JoinForTesting(); |
| 857 } | 862 } |
| 858 | 863 |
| 859 } // namespace internal | 864 } // namespace internal |
| 860 } // namespace base | 865 } // namespace base |
| OLD | NEW |