OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/worker_pool_posix.h" | 5 #include "base/threading/worker_pool_posix.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/synchronization/condition_variable.h" | 9 #include "base/synchronization/condition_variable.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 num_waiting_to_start_(num_waiting_to_start), | 99 num_waiting_to_start_(num_waiting_to_start), |
100 num_waiting_to_start_cv_(num_waiting_to_start_cv), | 100 num_waiting_to_start_cv_(num_waiting_to_start_cv), |
101 start_(start) {} | 101 start_(start) {} |
102 | 102 |
103 virtual void Run() { | 103 virtual void Run() { |
104 { | 104 { |
105 base::AutoLock num_waiting_to_start_locked(*num_waiting_to_start_lock_); | 105 base::AutoLock num_waiting_to_start_locked(*num_waiting_to_start_lock_); |
106 (*num_waiting_to_start_)++; | 106 (*num_waiting_to_start_)++; |
107 } | 107 } |
108 num_waiting_to_start_cv_->Signal(); | 108 num_waiting_to_start_cv_->Signal(); |
109 CHECK(start_->Wait()); | 109 start_->Wait(); |
110 incrementer_.Run(); | 110 incrementer_.Run(); |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 IncrementingTask incrementer_; | 114 IncrementingTask incrementer_; |
115 Lock* num_waiting_to_start_lock_; | 115 Lock* num_waiting_to_start_lock_; |
116 int* num_waiting_to_start_; | 116 int* num_waiting_to_start_; |
117 ConditionVariable* num_waiting_to_start_cv_; | 117 ConditionVariable* num_waiting_to_start_cv_; |
118 base::WaitableEvent* start_; | 118 base::WaitableEvent* start_; |
119 | 119 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // Add another non blocking task. There are no threads to reuse. | 261 // Add another non blocking task. There are no threads to reuse. |
262 pool_->PostTask(FROM_HERE, CreateNewIncrementingTask()); | 262 pool_->PostTask(FROM_HERE, CreateNewIncrementingTask()); |
263 WaitForIdleThreads(1); | 263 WaitForIdleThreads(1); |
264 | 264 |
265 EXPECT_EQ(3U, unique_threads_.size()); | 265 EXPECT_EQ(3U, unique_threads_.size()); |
266 EXPECT_EQ(1, peer_.num_idle_threads()); | 266 EXPECT_EQ(1, peer_.num_idle_threads()); |
267 EXPECT_EQ(4, counter_); | 267 EXPECT_EQ(4, counter_); |
268 } | 268 } |
269 | 269 |
270 } // namespace base | 270 } // namespace base |
OLD | NEW |