| 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/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 6 | 6 |
| 7 #include "base/synchronization/condition_variable.h" | 7 #include "base/synchronization/condition_variable.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return &cv_; | 142 return &cv_; |
| 143 } | 143 } |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 bool fired_; | 146 bool fired_; |
| 147 WaitableEvent* signaling_event_; // The WaitableEvent which woke us | 147 WaitableEvent* signaling_event_; // The WaitableEvent which woke us |
| 148 base::Lock lock_; | 148 base::Lock lock_; |
| 149 base::ConditionVariable cv_; | 149 base::ConditionVariable cv_; |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 bool WaitableEvent::Wait() { |
| 153 return TimedWait(TimeDelta::FromSeconds(-1)); |
| 154 } |
| 155 |
| 152 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { | 156 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { |
| 153 const Time end_time(Time::Now() + max_time); | 157 const Time end_time(Time::Now() + max_time); |
| 154 const bool finite_time = max_time.ToInternalValue() >= 0; | 158 const bool finite_time = max_time.ToInternalValue() >= 0; |
| 155 | 159 |
| 156 kernel_->lock_.Acquire(); | 160 kernel_->lock_.Acquire(); |
| 157 if (kernel_->signaled_) { | 161 if (kernel_->signaled_) { |
| 158 if (!kernel_->manual_reset_) { | 162 if (!kernel_->manual_reset_) { |
| 159 // In this case we were signaled when we had no waiters. Now that | 163 // In this case we were signaled when we had no waiters. Now that |
| 160 // someone has waited upon us, we can automatically reset. | 164 // someone has waited upon us, we can automatically reset. |
| 161 kernel_->signaled_ = false; | 165 kernel_->signaled_ = false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 201 |
| 198 if (finite_time) { | 202 if (finite_time) { |
| 199 const TimeDelta max_wait(end_time - current_time); | 203 const TimeDelta max_wait(end_time - current_time); |
| 200 sw.cv()->TimedWait(max_wait); | 204 sw.cv()->TimedWait(max_wait); |
| 201 } else { | 205 } else { |
| 202 sw.cv()->Wait(); | 206 sw.cv()->Wait(); |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 } | 209 } |
| 206 | 210 |
| 207 bool WaitableEvent::Wait() { | |
| 208 return TimedWait(TimeDelta::FromSeconds(-1)); | |
| 209 } | |
| 210 | |
| 211 // ----------------------------------------------------------------------------- | |
| 212 | |
| 213 | |
| 214 // ----------------------------------------------------------------------------- | 211 // ----------------------------------------------------------------------------- |
| 215 // Synchronous waiting on multiple objects. | 212 // Synchronous waiting on multiple objects. |
| 216 | 213 |
| 217 static bool // StrictWeakOrdering | 214 static bool // StrictWeakOrdering |
| 218 cmp_fst_addr(const std::pair<WaitableEvent*, unsigned> &a, | 215 cmp_fst_addr(const std::pair<WaitableEvent*, unsigned> &a, |
| 219 const std::pair<WaitableEvent*, unsigned> &b) { | 216 const std::pair<WaitableEvent*, unsigned> &b) { |
| 220 return a.first < b.first; | 217 return a.first < b.first; |
| 221 } | 218 } |
| 222 | 219 |
| 223 // static | 220 // static |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 return true; | 392 return true; |
| 396 } | 393 } |
| 397 } | 394 } |
| 398 | 395 |
| 399 return false; | 396 return false; |
| 400 } | 397 } |
| 401 | 398 |
| 402 // ----------------------------------------------------------------------------- | 399 // ----------------------------------------------------------------------------- |
| 403 | 400 |
| 404 } // namespace base | 401 } // namespace base |
| OLD | NEW |