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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/message_loop_proxy.h" | 18 #include "base/message_loop_proxy.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
22 #include "base/synchronization/condition_variable.h" | 22 #include "base/synchronization/condition_variable.h" |
23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
24 #include "base/threading/platform_thread.h" | 24 #include "base/threading/platform_thread.h" |
25 #include "base/threading/simple_thread.h" | 25 #include "base/threading/simple_thread.h" |
26 #include "base/time.h" | 26 #include "base/time.h" |
27 #include "base/tracked_objects.h" | 27 #include "base/tracked_objects.h" |
28 | 28 |
| 29 #if defined(OS_MACOSX) |
| 30 #include "base/mac/scoped_nsautorelease_pool.h" |
| 31 #endif |
| 32 |
29 namespace base { | 33 namespace base { |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 struct SequencedTask { | 37 struct SequencedTask { |
34 SequencedTask() | 38 SequencedTask() |
35 : sequence_token_id(0), | 39 : sequence_token_id(0), |
36 shutdown_behavior(SequencedWorkerPool::BLOCK_SHUTDOWN) {} | 40 shutdown_behavior(SequencedWorkerPool::BLOCK_SHUTDOWN) {} |
37 | 41 |
38 ~SequencedTask() {} | 42 ~SequencedTask() {} |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 { | 406 { |
403 AutoLock lock(lock_); | 407 AutoLock lock(lock_); |
404 DCHECK(thread_being_created_); | 408 DCHECK(thread_being_created_); |
405 thread_being_created_ = false; | 409 thread_being_created_ = false; |
406 std::pair<ThreadMap::iterator, bool> result = | 410 std::pair<ThreadMap::iterator, bool> result = |
407 threads_.insert( | 411 threads_.insert( |
408 std::make_pair(this_worker->tid(), make_linked_ptr(this_worker))); | 412 std::make_pair(this_worker->tid(), make_linked_ptr(this_worker))); |
409 DCHECK(result.second); | 413 DCHECK(result.second); |
410 | 414 |
411 while (true) { | 415 while (true) { |
| 416 #if defined(OS_MACOSX) |
| 417 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 418 #endif |
| 419 |
412 // See GetWork for what delete_these_outside_lock is doing. | 420 // See GetWork for what delete_these_outside_lock is doing. |
413 SequencedTask task; | 421 SequencedTask task; |
414 std::vector<Closure> delete_these_outside_lock; | 422 std::vector<Closure> delete_these_outside_lock; |
415 if (GetWork(&task, &delete_these_outside_lock)) { | 423 if (GetWork(&task, &delete_these_outside_lock)) { |
416 int new_thread_id = WillRunWorkerTask(task); | 424 int new_thread_id = WillRunWorkerTask(task); |
417 { | 425 { |
418 AutoUnlock unlock(lock_); | 426 AutoUnlock unlock(lock_); |
419 // There may be more work available, so wake up another | 427 // There may be more work available, so wake up another |
420 // worker thread. (Technically not required, since we | 428 // worker thread. (Technically not required, since we |
421 // already get a signal for each new task, but it doesn't | 429 // already get a signal for each new task, but it doesn't |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 void SequencedWorkerPool::SignalHasWorkForTesting() { | 803 void SequencedWorkerPool::SignalHasWorkForTesting() { |
796 inner_->SignalHasWorkForTesting(); | 804 inner_->SignalHasWorkForTesting(); |
797 } | 805 } |
798 | 806 |
799 void SequencedWorkerPool::Shutdown() { | 807 void SequencedWorkerPool::Shutdown() { |
800 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); | 808 DCHECK(constructor_message_loop_->BelongsToCurrentThread()); |
801 inner_->Shutdown(); | 809 inner_->Shutdown(); |
802 } | 810 } |
803 | 811 |
804 } // namespace base | 812 } // namespace base |
OLD | NEW |