| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 : lock_(), | 70 : lock_(), |
| 71 cond_var_(&lock_), | 71 cond_var_(&lock_), |
| 72 started_events_(0) { | 72 started_events_(0) { |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Each of these tasks appends the argument to the complete sequence vector | 75 // Each of these tasks appends the argument to the complete sequence vector |
| 76 // so calling code can see what order they finished in. | 76 // so calling code can see what order they finished in. |
| 77 void FastTask(int id) { | 77 void FastTask(int id) { |
| 78 SignalWorkerDone(id); | 78 SignalWorkerDone(id); |
| 79 } | 79 } |
| 80 |
| 80 void SlowTask(int id) { | 81 void SlowTask(int id) { |
| 81 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); | 82 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 82 SignalWorkerDone(id); | 83 SignalWorkerDone(id); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void BlockTask(int id, ThreadBlocker* blocker) { | 86 void BlockTask(int id, ThreadBlocker* blocker) { |
| 86 // Note that this task has started and signal anybody waiting for that | 87 // Note that this task has started and signal anybody waiting for that |
| 87 // to happen. | 88 // to happen. |
| 88 { | 89 { |
| 89 base::AutoLock lock(lock_); | 90 base::AutoLock lock(lock_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 return ret; | 120 return ret; |
| 120 } | 121 } |
| 121 | 122 |
| 122 void ClearCompleteSequence() { | 123 void ClearCompleteSequence() { |
| 123 base::AutoLock lock(lock_); | 124 base::AutoLock lock(lock_); |
| 124 complete_sequence_.clear(); | 125 complete_sequence_.clear(); |
| 125 started_events_ = 0; | 126 started_events_ = 0; |
| 126 } | 127 } |
| 127 | 128 |
| 128 private: | 129 private: |
| 130 friend class base::RefCountedThreadSafe<TestTracker>; |
| 131 ~TestTracker() {} |
| 132 |
| 129 void SignalWorkerDone(int id) { | 133 void SignalWorkerDone(int id) { |
| 130 { | 134 { |
| 131 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
| 132 complete_sequence_.push_back(id); | 136 complete_sequence_.push_back(id); |
| 133 } | 137 } |
| 134 cond_var_.Signal(); | 138 cond_var_.Signal(); |
| 135 } | 139 } |
| 136 | 140 |
| 137 // Protects the complete_sequence. | 141 // Protects the complete_sequence. |
| 138 base::Lock lock_; | 142 base::Lock lock_; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; | 533 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; |
| 530 }; | 534 }; |
| 531 | 535 |
| 532 INSTANTIATE_TYPED_TEST_CASE_P( | 536 INSTANTIATE_TYPED_TEST_CASE_P( |
| 533 SequencedWorkerPool, TaskRunnerTest, | 537 SequencedWorkerPool, TaskRunnerTest, |
| 534 SequencedWorkerPoolTaskRunnerTestDelegate); | 538 SequencedWorkerPoolTaskRunnerTestDelegate); |
| 535 | 539 |
| 536 } // namespace | 540 } // namespace |
| 537 | 541 |
| 538 } // namespace base | 542 } // namespace base |
| OLD | NEW |