| 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 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 // to stop redirecting tasks. It can also be called when the current state is | 1456 // to stop redirecting tasks. It can also be called when the current state is |
| 1457 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called | 1457 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called |
| 1458 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has | 1458 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has |
| 1459 // been created if this isn't called). | 1459 // been created if this isn't called). |
| 1460 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); | 1460 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1463 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
| 1464 const std::string& thread_name_prefix, | 1464 const std::string& thread_name_prefix, |
| 1465 base::TaskPriority task_priority) | 1465 base::TaskPriority task_priority) |
| 1466 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1466 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
| 1467 inner_(new Inner(this, | 1467 inner_(new Inner(this, |
| 1468 max_threads, | 1468 max_threads, |
| 1469 thread_name_prefix, | 1469 thread_name_prefix, |
| 1470 task_priority, | 1470 task_priority, |
| 1471 NULL)) {} | 1471 NULL)) {} |
| 1472 | 1472 |
| 1473 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1473 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
| 1474 const std::string& thread_name_prefix, | 1474 const std::string& thread_name_prefix, |
| 1475 base::TaskPriority task_priority, | 1475 base::TaskPriority task_priority, |
| 1476 TestingObserver* observer) | 1476 TestingObserver* observer) |
| 1477 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1477 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
| 1478 inner_(new Inner(this, | 1478 inner_(new Inner(this, |
| 1479 max_threads, | 1479 max_threads, |
| 1480 thread_name_prefix, | 1480 thread_name_prefix, |
| 1481 task_priority, | 1481 task_priority, |
| 1482 observer)) {} | 1482 observer)) {} |
| 1483 | 1483 |
| 1484 SequencedWorkerPool::~SequencedWorkerPool() {} | 1484 SequencedWorkerPool::~SequencedWorkerPool() {} |
| 1485 | 1485 |
| 1486 void SequencedWorkerPool::OnDestruct() const { | 1486 void SequencedWorkerPool::OnDestruct() const { |
| 1487 // Avoid deleting ourselves on a worker thread (which would deadlock). | 1487 // Avoid deleting ourselves on a worker thread (which would deadlock). |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 } else { | 1603 } else { |
| 1604 inner_->CleanupForTesting(); | 1604 inner_->CleanupForTesting(); |
| 1605 } | 1605 } |
| 1606 } | 1606 } |
| 1607 | 1607 |
| 1608 void SequencedWorkerPool::SignalHasWorkForTesting() { | 1608 void SequencedWorkerPool::SignalHasWorkForTesting() { |
| 1609 inner_->SignalHasWorkForTesting(); | 1609 inner_->SignalHasWorkForTesting(); |
| 1610 } | 1610 } |
| 1611 | 1611 |
| 1612 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1612 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
| 1613 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); | 1613 DCHECK(constructor_task_runner_->RunsTasksOnCurrentThread()); |
| 1614 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1614 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 bool SequencedWorkerPool::IsShutdownInProgress() { | 1617 bool SequencedWorkerPool::IsShutdownInProgress() { |
| 1618 return inner_->IsShutdownInProgress(); | 1618 return inner_->IsShutdownInProgress(); |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( | 1621 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( |
| 1622 SequenceToken sequence_token) const { | 1622 SequenceToken sequence_token) const { |
| 1623 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); | 1623 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 } // namespace base | 1626 } // namespace base |
| OLD | NEW |