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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const; | 282 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const; |
283 | 283 |
284 void CleanupForTesting(); | 284 void CleanupForTesting(); |
285 | 285 |
286 void SignalHasWorkForTesting(); | 286 void SignalHasWorkForTesting(); |
287 | 287 |
288 int GetWorkSignalCountForTesting() const; | 288 int GetWorkSignalCountForTesting() const; |
289 | 289 |
290 void Shutdown(int max_blocking_tasks_after_shutdown); | 290 void Shutdown(int max_blocking_tasks_after_shutdown); |
291 | 291 |
| 292 bool IsShutdownInProgress(); |
| 293 |
292 // Runs the worker loop on the background thread. | 294 // Runs the worker loop on the background thread. |
293 void ThreadLoop(Worker* this_worker); | 295 void ThreadLoop(Worker* this_worker); |
294 | 296 |
295 private: | 297 private: |
296 enum GetWorkStatus { | 298 enum GetWorkStatus { |
297 GET_WORK_FOUND, | 299 GET_WORK_FOUND, |
298 GET_WORK_NOT_FOUND, | 300 GET_WORK_NOT_FOUND, |
299 GET_WORK_WAIT, | 301 GET_WORK_WAIT, |
300 }; | 302 }; |
301 | 303 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 { | 673 { |
672 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 674 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
673 AutoLock lock(lock_); | 675 AutoLock lock(lock_); |
674 while (!CanShutdown()) | 676 while (!CanShutdown()) |
675 can_shutdown_cv_.Wait(); | 677 can_shutdown_cv_.Wait(); |
676 } | 678 } |
677 UMA_HISTOGRAM_TIMES("SequencedWorkerPool.ShutdownDelayTime", | 679 UMA_HISTOGRAM_TIMES("SequencedWorkerPool.ShutdownDelayTime", |
678 TimeTicks::Now() - shutdown_wait_begin); | 680 TimeTicks::Now() - shutdown_wait_begin); |
679 } | 681 } |
680 | 682 |
| 683 bool SequencedWorkerPool::Inner::IsShutdownInProgress() { |
| 684 AutoLock lock(lock_); |
| 685 return shutdown_called_; |
| 686 } |
| 687 |
681 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { | 688 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { |
682 { | 689 { |
683 AutoLock lock(lock_); | 690 AutoLock lock(lock_); |
684 DCHECK(thread_being_created_); | 691 DCHECK(thread_being_created_); |
685 thread_being_created_ = false; | 692 thread_being_created_ = false; |
686 std::pair<ThreadMap::iterator, bool> result = | 693 std::pair<ThreadMap::iterator, bool> result = |
687 threads_.insert( | 694 threads_.insert( |
688 std::make_pair(this_worker->tid(), make_linked_ptr(this_worker))); | 695 std::make_pair(this_worker->tid(), make_linked_ptr(this_worker))); |
689 DCHECK(result.second); | 696 DCHECK(result.second); |
690 | 697 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 | 1236 |
1230 void SequencedWorkerPool::SignalHasWorkForTesting() { | 1237 void SequencedWorkerPool::SignalHasWorkForTesting() { |
1231 inner_->SignalHasWorkForTesting(); | 1238 inner_->SignalHasWorkForTesting(); |
1232 } | 1239 } |
1233 | 1240 |
1234 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1241 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
1235 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); | 1242 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); |
1236 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1243 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
1237 } | 1244 } |
1238 | 1245 |
| 1246 bool SequencedWorkerPool::IsShutdownInProgress() { |
| 1247 return inner_->IsShutdownInProgress(); |
| 1248 } |
| 1249 |
1239 } // namespace base | 1250 } // namespace base |
OLD | NEW |