| 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/heap_profiler.h" | 38 #include "base/trace_event/heap_profiler.h" |
| 39 #include "base/trace_event/trace_event.h" | 39 #include "base/trace_event/trace_event.h" |
| 40 #include "base/tracked_objects.h" | 40 #include "base/tracked_objects.h" |
| 41 #include "base/tracking_info.h" | 41 #include "base/tracking_info.h" |
| 42 #include "build/build_config.h" | 42 #include "build/build_config.h" |
| 43 | 43 |
| 44 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 45 #include "base/mac/scoped_nsautorelease_pool.h" | 45 #include "base/mac/scoped_nsautorelease_pool.h" |
| 46 #elif defined(OS_WIN) | 46 #elif defined(OS_WIN) |
| (...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 // to stop redirecting tasks. It can also be called when the current state is | 1460 // to stop redirecting tasks. It can also be called when the current state is |
| 1461 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called | 1461 // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called |
| 1462 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has | 1462 // (RedirectToTaskSchedulerForProcess() cannot be called after a worker has |
| 1463 // been created if this isn't called). | 1463 // been created if this isn't called). |
| 1464 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); | 1464 subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1467 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
| 1468 const std::string& thread_name_prefix, | 1468 const std::string& thread_name_prefix, |
| 1469 base::TaskPriority task_priority) | 1469 base::TaskPriority task_priority) |
| 1470 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1470 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
| 1471 inner_(new Inner(this, | 1471 inner_(new Inner(this, |
| 1472 max_threads, | 1472 max_threads, |
| 1473 thread_name_prefix, | 1473 thread_name_prefix, |
| 1474 task_priority, | 1474 task_priority, |
| 1475 NULL)) {} | 1475 NULL)) {} |
| 1476 | 1476 |
| 1477 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, | 1477 SequencedWorkerPool::SequencedWorkerPool(size_t max_threads, |
| 1478 const std::string& thread_name_prefix, | 1478 const std::string& thread_name_prefix, |
| 1479 base::TaskPriority task_priority, | 1479 base::TaskPriority task_priority, |
| 1480 TestingObserver* observer) | 1480 TestingObserver* observer) |
| 1481 : constructor_task_runner_(ThreadTaskRunnerHandle::Get()), | 1481 : constructor_task_runner_(SequencedTaskRunnerHandle::Get()), |
| 1482 inner_(new Inner(this, | 1482 inner_(new Inner(this, |
| 1483 max_threads, | 1483 max_threads, |
| 1484 thread_name_prefix, | 1484 thread_name_prefix, |
| 1485 task_priority, | 1485 task_priority, |
| 1486 observer)) {} | 1486 observer)) {} |
| 1487 | 1487 |
| 1488 SequencedWorkerPool::~SequencedWorkerPool() {} | 1488 SequencedWorkerPool::~SequencedWorkerPool() {} |
| 1489 | 1489 |
| 1490 void SequencedWorkerPool::OnDestruct() const { | 1490 void SequencedWorkerPool::OnDestruct() const { |
| 1491 // Avoid deleting ourselves on a worker thread (which would deadlock). | 1491 // Avoid deleting ourselves on a worker thread (which would deadlock). |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 } else { | 1607 } else { |
| 1608 inner_->CleanupForTesting(); | 1608 inner_->CleanupForTesting(); |
| 1609 } | 1609 } |
| 1610 } | 1610 } |
| 1611 | 1611 |
| 1612 void SequencedWorkerPool::SignalHasWorkForTesting() { | 1612 void SequencedWorkerPool::SignalHasWorkForTesting() { |
| 1613 inner_->SignalHasWorkForTesting(); | 1613 inner_->SignalHasWorkForTesting(); |
| 1614 } | 1614 } |
| 1615 | 1615 |
| 1616 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1616 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
| 1617 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); | 1617 DCHECK(constructor_task_runner_->RunsTasksOnCurrentThread()); |
| 1618 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1618 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 bool SequencedWorkerPool::IsShutdownInProgress() { | 1621 bool SequencedWorkerPool::IsShutdownInProgress() { |
| 1622 return inner_->IsShutdownInProgress(); | 1622 return inner_->IsShutdownInProgress(); |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( | 1625 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( |
| 1626 SequenceToken sequence_token) const { | 1626 SequenceToken sequence_token) const { |
| 1627 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); | 1627 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); |
| 1628 } | 1628 } |
| 1629 | 1629 |
| 1630 } // namespace base | 1630 } // namespace base |
| OLD | NEW |