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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 static_cast<int>(SKIP_ON_SHUTDOWN), | 819 static_cast<int>(SKIP_ON_SHUTDOWN), |
820 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " | 820 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " |
821 "SKIP_ON_SHUTDOWN."); | 821 "SKIP_ON_SHUTDOWN."); |
822 static_assert(static_cast<int>(TaskShutdownBehavior::BLOCK_SHUTDOWN) == | 822 static_assert(static_cast<int>(TaskShutdownBehavior::BLOCK_SHUTDOWN) == |
823 static_cast<int>(BLOCK_SHUTDOWN), | 823 static_cast<int>(BLOCK_SHUTDOWN), |
824 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " | 824 "TaskShutdownBehavior and WorkerShutdown enum mismatch for " |
825 "BLOCK_SHUTDOWN."); | 825 "BLOCK_SHUTDOWN."); |
826 | 826 |
827 const TaskShutdownBehavior task_shutdown_behavior = | 827 const TaskShutdownBehavior task_shutdown_behavior = |
828 static_cast<TaskShutdownBehavior>(sequenced.shutdown_behavior); | 828 static_cast<TaskShutdownBehavior>(sequenced.shutdown_behavior); |
829 const TaskTraits traits = TaskTraits() | 829 const TaskTraits traits = {MayBlock(), WithBaseSyncPrimitives(), |
830 .MayBlock() | 830 task_priority_, task_shutdown_behavior}; |
831 .WithBaseSyncPrimitives() | |
832 .WithPriority(task_priority_) | |
833 .WithShutdownBehavior(task_shutdown_behavior); | |
834 return GetTaskSchedulerTaskRunner(sequenced.sequence_token_id, traits) | 831 return GetTaskSchedulerTaskRunner(sequenced.sequence_token_id, traits) |
835 ->PostDelayedTask(sequenced.posted_from, std::move(sequenced.task), | 832 ->PostDelayedTask(sequenced.posted_from, std::move(sequenced.task), |
836 delay); | 833 delay); |
837 } | 834 } |
838 | 835 |
839 scoped_refptr<TaskRunner> | 836 scoped_refptr<TaskRunner> |
840 SequencedWorkerPool::Inner::GetTaskSchedulerTaskRunner( | 837 SequencedWorkerPool::Inner::GetTaskSchedulerTaskRunner( |
841 int sequence_token_id, | 838 int sequence_token_id, |
842 const TaskTraits& traits) { | 839 const TaskTraits& traits) { |
843 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER, g_all_pools_state); | 840 DCHECK_EQ(AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER, g_all_pools_state); |
(...skipping 29 matching lines...) Expand all Loading... |
873 } | 870 } |
874 | 871 |
875 return task_runner; | 872 return task_runner; |
876 } | 873 } |
877 | 874 |
878 bool SequencedWorkerPool::Inner::RunsTasksOnCurrentThread() const { | 875 bool SequencedWorkerPool::Inner::RunsTasksOnCurrentThread() const { |
879 AutoLock lock(lock_); | 876 AutoLock lock(lock_); |
880 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { | 877 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { |
881 if (!runs_tasks_on_verifier_) { | 878 if (!runs_tasks_on_verifier_) { |
882 runs_tasks_on_verifier_ = CreateTaskRunnerWithTraits( | 879 runs_tasks_on_verifier_ = CreateTaskRunnerWithTraits( |
883 TaskTraits().MayBlock().WithBaseSyncPrimitives().WithPriority( | 880 {MayBlock(), WithBaseSyncPrimitives(), task_priority_}); |
884 task_priority_)); | |
885 } | 881 } |
886 return runs_tasks_on_verifier_->RunsTasksOnCurrentThread(); | 882 return runs_tasks_on_verifier_->RunsTasksOnCurrentThread(); |
887 } else { | 883 } else { |
888 return ContainsKey(threads_, PlatformThread::CurrentId()); | 884 return ContainsKey(threads_, PlatformThread::CurrentId()); |
889 } | 885 } |
890 } | 886 } |
891 | 887 |
892 bool SequencedWorkerPool::Inner::IsRunningSequenceOnCurrentThread( | 888 bool SequencedWorkerPool::Inner::IsRunningSequenceOnCurrentThread( |
893 SequenceToken sequence_token) const { | 889 SequenceToken sequence_token) const { |
894 DCHECK(sequence_token.IsValid()); | 890 DCHECK(sequence_token.IsValid()); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 bool SequencedWorkerPool::IsShutdownInProgress() { | 1640 bool SequencedWorkerPool::IsShutdownInProgress() { |
1645 return inner_->IsShutdownInProgress(); | 1641 return inner_->IsShutdownInProgress(); |
1646 } | 1642 } |
1647 | 1643 |
1648 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( | 1644 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( |
1649 SequenceToken sequence_token) const { | 1645 SequenceToken sequence_token) const { |
1650 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); | 1646 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); |
1651 } | 1647 } |
1652 | 1648 |
1653 } // namespace base | 1649 } // namespace base |
OLD | NEW |