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 12 matching lines...) Expand all Loading... |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
25 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
26 #include "base/stl_util.h" | 26 #include "base/stl_util.h" |
27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
28 #include "base/synchronization/condition_variable.h" | 28 #include "base/synchronization/condition_variable.h" |
29 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
30 #include "base/task_scheduler/post_task.h" | 30 #include "base/task_scheduler/post_task.h" |
31 #include "base/task_scheduler/task_scheduler.h" | 31 #include "base/task_scheduler/task_scheduler.h" |
32 #include "base/threading/platform_thread.h" | 32 #include "base/threading/platform_thread.h" |
| 33 #include "base/threading/sequenced_task_runner_handle.h" |
33 #include "base/threading/simple_thread.h" | 34 #include "base/threading/simple_thread.h" |
34 #include "base/threading/thread_local.h" | 35 #include "base/threading/thread_local.h" |
35 #include "base/threading/thread_restrictions.h" | 36 #include "base/threading/thread_restrictions.h" |
36 #include "base/threading/thread_task_runner_handle.h" | |
37 #include "base/time/time.h" | 37 #include "base/time/time.h" |
38 #include "base/trace_event/trace_event.h" | 38 #include "base/trace_event/trace_event.h" |
39 #include "base/tracked_objects.h" | 39 #include "base/tracked_objects.h" |
40 #include "base/tracking_info.h" | 40 #include "base/tracking_info.h" |
41 #include "build/build_config.h" | 41 #include "build/build_config.h" |
42 | 42 |
43 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
44 #include "base/mac/scoped_nsautorelease_pool.h" | 44 #include "base/mac/scoped_nsautorelease_pool.h" |
45 #elif defined(OS_WIN) | 45 #elif defined(OS_WIN) |
46 #include "base/win/scoped_com_initializer.h" | 46 #include "base/win/scoped_com_initializer.h" |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 // to stop redirecting tasks. It can also be called when the current state is | 1455 // to stop redirecting tasks. It can also be called when the current state is |
1456 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called | 1456 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called |
1457 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has | 1457 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has |
1458 // been created if this isn't called). | 1458 // been created if this isn't called). |
1459 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); | 1459 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); |
1460 } | 1460 } |
1461 | 1461 |
1462 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1462 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
1463 const std::string& thread_name_prefix, | 1463 const std::string& thread_name_prefix, |
1464 base::TaskPriority task_priority) | 1464 base::TaskPriority task_priority) |
1465 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1465 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
1466 inner_(new Inner(this, | 1466 inner_(new Inner(this, |
1467 max_threads, | 1467 max_threads, |
1468 thread_name_prefix, | 1468 thread_name_prefix, |
1469 task_priority, | 1469 task_priority, |
1470 NULL)) {} | 1470 NULL)) {} |
1471 | 1471 |
1472 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1472 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
1473 const std::string& thread_name_prefix, | 1473 const std::string& thread_name_prefix, |
1474 base::TaskPriority task_priority, | 1474 base::TaskPriority task_priority, |
1475 TestingObserver* observer) | 1475 TestingObserver* observer) |
1476 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1476 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
1477 inner_(new Inner(this, | 1477 inner_(new Inner(this, |
1478 max_threads, | 1478 max_threads, |
1479 thread_name_prefix, | 1479 thread_name_prefix, |
1480 task_priority, | 1480 task_priority, |
1481 observer)) {} | 1481 observer)) {} |
1482 | 1482 |
1483 SequencedWorkerPool::~SequencedWorkerPool() {} | 1483 SequencedWorkerPool::~SequencedWorkerPool() {} |
1484 | 1484 |
1485 void SequencedWorkerPool::OnDestruct() const { | 1485 void SequencedWorkerPool::OnDestruct() const { |
1486 // Avoid deleting ourselves on a worker thread (which would deadlock). | 1486 // Avoid deleting ourselves on a worker thread (which would deadlock). |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 } else { | 1602 } else { |
1603 inner_->CleanupForTesting(); | 1603 inner_->CleanupForTesting(); |
1604 } | 1604 } |
1605 } | 1605 } |
1606 | 1606 |
1607 void SequencedWorkerPool::SignalHasWorkForTesting() { | 1607 void SequencedWorkerPool::SignalHasWorkForTesting() { |
1608 inner_->SignalHasWorkForTesting(); | 1608 inner_->SignalHasWorkForTesting(); |
1609 } | 1609 } |
1610 | 1610 |
1611 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1611 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
1612 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); | 1612 DCHECK(constructor_task_runner_->RunsTasksOnCurrentThread()); |
1613 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1613 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
1614 } | 1614 } |
1615 | 1615 |
1616 bool SequencedWorkerPool::IsShutdownInProgress() { | 1616 bool SequencedWorkerPool::IsShutdownInProgress() { |
1617 return inner_->IsShutdownInProgress(); | 1617 return inner_->IsShutdownInProgress(); |
1618 } | 1618 } |
1619 | 1619 |
1620 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( | 1620 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( |
1621 SequenceToken sequence_token) const { | 1621 SequenceToken sequence_token) const { |
1622 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); | 1622 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); |
1623 } | 1623 } |
1624 | 1624 |
1625 } // namespace base | 1625 } // namespace base |
OLD | NEW |