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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/debug/activity_tracker.h" | 10 #include "base/debug/activity_tracker.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 146 } |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 bool fired_; | 149 bool fired_; |
| 150 WaitableEvent* signaling_event_; // The WaitableEvent which woke us | 150 WaitableEvent* signaling_event_; // The WaitableEvent which woke us |
| 151 base::Lock lock_; | 151 base::Lock lock_; |
| 152 base::ConditionVariable cv_; | 152 base::ConditionVariable cv_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 void WaitableEvent::Wait() { | 155 void WaitableEvent::Wait() { |
| 156 bool result = TimedWait(TimeDelta::FromSeconds(-1)); | 156 bool result = TimedWaitUntil(TimeTicks::Max()); |
| 157 DCHECK(result) << "TimedWait() should never fail with infinite timeout"; | 157 DCHECK(result) << "TimedWait() should never fail with infinite timeout"; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool WaitableEvent::TimedWait(const TimeDelta& max_time) { | 160 bool WaitableEvent::TimedWait(const TimeDelta& max_delta) { |
|
danakj
2016/11/29 02:46:45
one more nit: i think wait_delta or just delta eve
stanisc
2016/11/29 22:33:20
Done.
| |
| 161 // TimeTicks takes care of overflow including the cases when max_delta | |
| 162 // is a maximum value. | |
| 163 return TimedWaitUntil(TimeTicks::Now() + max_delta); | |
| 164 } | |
| 165 | |
| 166 bool WaitableEvent::TimedWaitUntil(const TimeTicks& end_time) { | |
| 167 base::ThreadRestrictions::AssertWaitAllowed(); | |
| 161 // Record the event that this thread is blocking upon (for hang diagnosis). | 168 // Record the event that this thread is blocking upon (for hang diagnosis). |
| 162 base::debug::ScopedEventWaitActivity event_activity(this); | 169 base::debug::ScopedEventWaitActivity event_activity(this); |
| 163 | 170 |
| 164 base::ThreadRestrictions::AssertWaitAllowed(); | 171 const bool finite_time = !end_time.is_max(); |
| 165 const TimeTicks end_time(TimeTicks::Now() + max_time); | |
| 166 const bool finite_time = max_time.ToInternalValue() >= 0; | |
| 167 | 172 |
| 168 kernel_->lock_.Acquire(); | 173 kernel_->lock_.Acquire(); |
| 169 if (kernel_->signaled_) { | 174 if (kernel_->signaled_) { |
| 170 if (!kernel_->manual_reset_) { | 175 if (!kernel_->manual_reset_) { |
| 171 // In this case we were signaled when we had no waiters. Now that | 176 // In this case we were signaled when we had no waiters. Now that |
| 172 // someone has waited upon us, we can automatically reset. | 177 // someone has waited upon us, we can automatically reset. |
| 173 kernel_->signaled_ = false; | 178 kernel_->signaled_ = false; |
| 174 } | 179 } |
| 175 | 180 |
| 176 kernel_->lock_.Release(); | 181 kernel_->lock_.Release(); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 return true; | 418 return true; |
| 414 } | 419 } |
| 415 } | 420 } |
| 416 | 421 |
| 417 return false; | 422 return false; |
| 418 } | 423 } |
| 419 | 424 |
| 420 // ----------------------------------------------------------------------------- | 425 // ----------------------------------------------------------------------------- |
| 421 | 426 |
| 422 } // namespace base | 427 } // namespace base |
| OLD | NEW |