| 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 <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 685 } |
| 686 | 686 |
| 687 // SequencedWorkerPool -------------------------------------------------------- | 687 // SequencedWorkerPool -------------------------------------------------------- |
| 688 | 688 |
| 689 SequencedWorkerPool::SequencedWorkerPool( | 689 SequencedWorkerPool::SequencedWorkerPool( |
| 690 size_t max_threads, | 690 size_t max_threads, |
| 691 const std::string& thread_name_prefix) | 691 const std::string& thread_name_prefix) |
| 692 : constructor_message_loop_(MessageLoopProxy::current()), | 692 : constructor_message_loop_(MessageLoopProxy::current()), |
| 693 inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 693 inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| 694 max_threads, thread_name_prefix, NULL)) { | 694 max_threads, thread_name_prefix, NULL)) { |
| 695 DCHECK(constructor_message_loop_.get()); | |
| 696 } | 695 } |
| 697 | 696 |
| 698 SequencedWorkerPool::SequencedWorkerPool( | 697 SequencedWorkerPool::SequencedWorkerPool( |
| 699 size_t max_threads, | 698 size_t max_threads, |
| 700 const std::string& thread_name_prefix, | 699 const std::string& thread_name_prefix, |
| 701 TestingObserver* observer) | 700 TestingObserver* observer) |
| 702 : constructor_message_loop_(MessageLoopProxy::current()), | 701 : constructor_message_loop_(MessageLoopProxy::current()), |
| 703 inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 702 inner_(new Inner(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| 704 max_threads, thread_name_prefix, observer)) { | 703 max_threads, thread_name_prefix, observer)) { |
| 705 DCHECK(constructor_message_loop_.get()); | |
| 706 } | 704 } |
| 707 | 705 |
| 708 SequencedWorkerPool::~SequencedWorkerPool() {} | 706 SequencedWorkerPool::~SequencedWorkerPool() {} |
| 709 | 707 |
| 710 void SequencedWorkerPool::OnDestruct() const { | 708 void SequencedWorkerPool::OnDestruct() const { |
| 711 // TODO(akalin): Once we can easily check if we're on a worker | 709 DCHECK(constructor_message_loop_.get()); |
| 712 // thread or not, use that instead of restricting destruction to | 710 // Avoid deleting ourselves on a worker thread (which would |
| 713 // only the constructor message loop. | 711 // deadlock). |
| 714 if (constructor_message_loop_->BelongsToCurrentThread()) | 712 if (RunsTasksOnCurrentThread()) { |
| 713 constructor_message_loop_->DeleteSoon(FROM_HERE, this); |
| 714 } else { |
| 715 delete this; | 715 delete this; |
| 716 else | 716 } |
| 717 constructor_message_loop_->DeleteSoon(FROM_HERE, this); | |
| 718 } | 717 } |
| 719 | 718 |
| 720 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { | 719 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetSequenceToken() { |
| 721 return inner_->GetSequenceToken(); | 720 return inner_->GetSequenceToken(); |
| 722 } | 721 } |
| 723 | 722 |
| 724 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( | 723 SequencedWorkerPool::SequenceToken SequencedWorkerPool::GetNamedSequenceToken( |
| 725 const std::string& name) { | 724 const std::string& name) { |
| 726 return inner_->GetNamedSequenceToken(name); | 725 return inner_->GetNamedSequenceToken(name); |
| 727 } | 726 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 void SequencedWorkerPool::SignalHasWorkForTesting() { | 795 void SequencedWorkerPool::SignalHasWorkForTesting() { |
| 797 inner_->SignalHasWorkForTesting(); | 796 inner_->SignalHasWorkForTesting(); |
| 798 } | 797 } |
| 799 | 798 |
| 800 void SequencedWorkerPool::Shutdown() { | 799 void SequencedWorkerPool::Shutdown() { |
| 801 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); | 800 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); |
| 802 inner_->Shutdown(); | 801 inner_->Shutdown(); |
| 803 } | 802 } |
| 804 | 803 |
| 805 } // namespace base | 804 } // namespace base |
| OLD | NEW |