OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/threading/sequenced_worker_pool.h" | 5 #include "base/threading/sequenced_worker_pool.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 | 959 |
960 TEST_F(SequencedWorkerPoolTest, GetSequencedTaskRunnerForCurrentThread) { | 960 TEST_F(SequencedWorkerPoolTest, GetSequencedTaskRunnerForCurrentThread) { |
961 EnsureAllWorkersCreated(); | 961 EnsureAllWorkersCreated(); |
962 | 962 |
963 // The current thread should not have a sequenced task runner from a | 963 // The current thread should not have a sequenced task runner from a |
964 // worker pool. | 964 // worker pool. |
965 scoped_refptr<SequencedTaskRunner> local_task_runner = | 965 scoped_refptr<SequencedTaskRunner> local_task_runner = |
966 SequencedWorkerPool::GetSequencedTaskRunnerForCurrentThread(); | 966 SequencedWorkerPool::GetSequencedTaskRunnerForCurrentThread(); |
967 EXPECT_FALSE(local_task_runner); | 967 EXPECT_FALSE(local_task_runner); |
968 | 968 |
969 WaitableEvent event(false, false); | 969 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 970 WaitableEvent::InitialState::NOT_SIGNALED); |
970 Closure signal = Bind(&WaitableEvent::Signal, Unretained(&event)); | 971 Closure signal = Bind(&WaitableEvent::Signal, Unretained(&event)); |
971 scoped_refptr<SequencedTaskRunner> task_runner_1 = | 972 scoped_refptr<SequencedTaskRunner> task_runner_1 = |
972 pool()->GetSequencedTaskRunner(SequencedWorkerPool::GetSequenceToken()); | 973 pool()->GetSequencedTaskRunner(SequencedWorkerPool::GetSequenceToken()); |
973 scoped_refptr<SequencedTaskRunner> task_runner_2 = | 974 scoped_refptr<SequencedTaskRunner> task_runner_2 = |
974 pool()->GetSequencedTaskRunner(SequencedWorkerPool::GetSequenceToken()); | 975 pool()->GetSequencedTaskRunner(SequencedWorkerPool::GetSequenceToken()); |
975 task_runner_1->PostTask( | 976 task_runner_1->PostTask( |
976 FROM_HERE, Bind(&VerifyCurrentSequencedTaskRunner, | 977 FROM_HERE, Bind(&VerifyCurrentSequencedTaskRunner, |
977 base::Unretained(task_runner_1.get()), true, signal)); | 978 base::Unretained(task_runner_1.get()), true, signal)); |
978 event.Wait(); | 979 event.Wait(); |
979 task_runner_2->PostTask( | 980 task_runner_2->PostTask( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 task_runner->PostTask(FROM_HERE, Bind(&ChecksSequenceOnDestruction::DoNothing, | 1019 task_runner->PostTask(FROM_HERE, Bind(&ChecksSequenceOnDestruction::DoNothing, |
1019 std::move(check_sequence))); | 1020 std::move(check_sequence))); |
1020 | 1021 |
1021 // Post the callback afterwards, so we can be sure the first task completed. | 1022 // Post the callback afterwards, so we can be sure the first task completed. |
1022 task_runner->PostTask(FROM_HERE, callback); | 1023 task_runner->PostTask(FROM_HERE, callback); |
1023 } | 1024 } |
1024 | 1025 |
1025 TEST_F(SequencedWorkerPoolTest, CheckSequenceOnDestruction) { | 1026 TEST_F(SequencedWorkerPoolTest, CheckSequenceOnDestruction) { |
1026 EnsureAllWorkersCreated(); | 1027 EnsureAllWorkersCreated(); |
1027 | 1028 |
1028 WaitableEvent event(false, false); | 1029 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1030 WaitableEvent::InitialState::NOT_SIGNALED); |
1029 Closure signal = Bind(&WaitableEvent::Signal, Unretained(&event)); | 1031 Closure signal = Bind(&WaitableEvent::Signal, Unretained(&event)); |
1030 pool()->PostWorkerTask(FROM_HERE, Bind(&VerifySequenceOnDestruction, signal)); | 1032 pool()->PostWorkerTask(FROM_HERE, Bind(&VerifySequenceOnDestruction, signal)); |
1031 event.Wait(); | 1033 event.Wait(); |
1032 } | 1034 } |
1033 | 1035 |
1034 TEST_F(SequencedWorkerPoolTest, ShutsDownCleanWithContinueOnShutdown) { | 1036 TEST_F(SequencedWorkerPoolTest, ShutsDownCleanWithContinueOnShutdown) { |
1035 scoped_refptr<SequencedTaskRunner> task_runner = | 1037 scoped_refptr<SequencedTaskRunner> task_runner = |
1036 pool()->GetSequencedTaskRunnerWithShutdownBehavior( | 1038 pool()->GetSequencedTaskRunnerWithShutdownBehavior( |
1037 pool()->GetSequenceToken(), | 1039 pool()->GetSequenceToken(), |
1038 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 1040 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, | 1162 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, |
1161 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); | 1163 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
1162 INSTANTIATE_TYPED_TEST_CASE_P( | 1164 INSTANTIATE_TYPED_TEST_CASE_P( |
1163 SequencedWorkerPoolSequencedTaskRunner, | 1165 SequencedWorkerPoolSequencedTaskRunner, |
1164 SequencedTaskRunnerDelayedTest, | 1166 SequencedTaskRunnerDelayedTest, |
1165 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); | 1167 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
1166 | 1168 |
1167 } // namespace | 1169 } // namespace |
1168 | 1170 |
1169 } // namespace base | 1171 } // namespace base |
OLD | NEW |