Chromium Code Reviews| 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 <vector> | 10 #include <vector> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 tracked_objects::Location location; | 38 tracked_objects::Location location; |
| 39 Closure task; | 39 Closure task; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 // Worker --------------------------------------------------------------------- | 44 // Worker --------------------------------------------------------------------- |
| 45 | 45 |
| 46 class SequencedWorkerPool::Worker : public SimpleThread { | 46 class SequencedWorkerPool::Worker : public SimpleThread { |
| 47 public: | 47 public: |
| 48 // Hold a ref to |worker_pool|, since we want to keep it around even | 48 // Hold a (cyclic) ref to |worker_pool|, since we want to keep it |
| 49 // if it doesn't join our thread. Note that this (deliberately) | 49 // around as long as we are running. Note that this (deliberately) |
|
brettw
2012/02/28 04:38:46
Is the leaks on shutdown comment still valid? If s
akalin
2012/02/28 22:10:33
Done.
| |
| 50 // leaks on shutdown. | 50 // leaks on shutdown. |
| 51 Worker(const scoped_refptr<SequencedWorkerPool>& worker_pool, | 51 Worker(const scoped_refptr<SequencedWorkerPool>& worker_pool, |
| 52 int thread_number, | 52 int thread_number, |
| 53 const std::string& thread_name_prefix); | 53 const std::string& thread_name_prefix); |
| 54 virtual ~Worker(); | 54 virtual ~Worker(); |
| 55 | 55 |
| 56 // SimpleThread implementation. This actually runs the background thread. | 56 // SimpleThread implementation. This actually runs the background thread. |
| 57 virtual void Run() OVERRIDE; | 57 virtual void Run() OVERRIDE; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 const scoped_refptr<SequencedWorkerPool> worker_pool_; | 60 scoped_refptr<SequencedWorkerPool> worker_pool_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(Worker); | 62 DISALLOW_COPY_AND_ASSIGN(Worker); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Inner ---------------------------------------------------------------------- | 65 // Inner ---------------------------------------------------------------------- |
| 66 | 66 |
| 67 class SequencedWorkerPool::Inner { | 67 class SequencedWorkerPool::Inner { |
| 68 public: | 68 public: |
| 69 // Take a raw pointer to |worker| to avoid cycles (since we're owned | 69 // Take a raw pointer to |worker| to avoid cycles (since we're owned |
| 70 // by it). | 70 // by it). |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 SequencedWorkerPool::Worker::~Worker() { | 219 SequencedWorkerPool::Worker::~Worker() { |
| 220 } | 220 } |
| 221 | 221 |
| 222 void SequencedWorkerPool::Worker::Run() { | 222 void SequencedWorkerPool::Worker::Run() { |
| 223 // Just jump back to the Inner object to run the thread, since it has all the | 223 // Just jump back to the Inner object to run the thread, since it has all the |
| 224 // tracking information and queues. It might be more natural to implement | 224 // tracking information and queues. It might be more natural to implement |
| 225 // using DelegateSimpleThread and have Inner implement the Delegate to avoid | 225 // using DelegateSimpleThread and have Inner implement the Delegate to avoid |
| 226 // having these worker objects at all, but that method lacks the ability to | 226 // having these worker objects at all, but that method lacks the ability to |
| 227 // send thread-specific information easily to the thread loop. | 227 // send thread-specific information easily to the thread loop. |
| 228 worker_pool_->inner_->ThreadLoop(this); | 228 worker_pool_->inner_->ThreadLoop(this); |
| 229 // Release our cyclic reference once we're done. | |
| 230 worker_pool_ = NULL; | |
| 229 } | 231 } |
| 230 | 232 |
| 231 // Inner definitions --------------------------------------------------------- | 233 // Inner definitions --------------------------------------------------------- |
| 232 | 234 |
| 233 SequencedWorkerPool::Inner::Inner( | 235 SequencedWorkerPool::Inner::Inner( |
| 234 SequencedWorkerPool* worker_pool, | 236 SequencedWorkerPool* worker_pool, |
| 235 size_t max_threads, | 237 size_t max_threads, |
| 236 const std::string& thread_name_prefix) | 238 const std::string& thread_name_prefix) |
| 237 : worker_pool_(worker_pool), | 239 : worker_pool_(worker_pool), |
| 238 last_sequence_number_(0), | 240 last_sequence_number_(0), |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 | 697 |
| 696 void SequencedWorkerPool::Shutdown() { | 698 void SequencedWorkerPool::Shutdown() { |
| 697 inner_->Shutdown(); | 699 inner_->Shutdown(); |
| 698 } | 700 } |
| 699 | 701 |
| 700 void SequencedWorkerPool::SetTestingObserver(TestingObserver* observer) { | 702 void SequencedWorkerPool::SetTestingObserver(TestingObserver* observer) { |
| 701 inner_->SetTestingObserver(observer); | 703 inner_->SetTestingObserver(observer); |
| 702 } | 704 } |
| 703 | 705 |
| 704 } // namespace base | 706 } // namespace base |
| OLD | NEW |