Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: base/synchronization/waitable_event_posix.cc

Issue 2433773005: Move OS_WIN specific logic in MessagePumpDefault::Run into waitable_event_win.cc (Closed)
Patch Set: Addressed CR feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/synchronization/waitable_event.h ('k') | base/synchronization/waitable_event_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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& wait_delta) {
161 // TimeTicks takes care of overflow including the cases when wait_delta
162 // is a maximum value.
163 return TimedWaitUntil(TimeTicks::Now() + wait_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
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
OLDNEW
« no previous file with comments | « base/synchronization/waitable_event.h ('k') | base/synchronization/waitable_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698