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

Unified Diff: base/synchronization/waitable_event_posix.cc

Issue 999753005: Make sure that WaitableEvent::TimedWait works fine with large timeouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 5 years, 9 months 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/waitable_event_posix.cc
diff --git a/base/synchronization/waitable_event_posix.cc b/base/synchronization/waitable_event_posix.cc
index 696ffc7a02abe5a1c21e429032b217fd7f142c91..04a262b721d80186011c2d5e3370396805765d6c 100644
--- a/base/synchronization/waitable_event_posix.cc
+++ b/base/synchronization/waitable_event_posix.cc
@@ -151,14 +151,14 @@ class SyncWaiter : public WaitableEvent::Waiter {
};
void WaitableEvent::Wait() {
- bool result = TimedWait(TimeDelta::FromSeconds(-1));
+ bool result = TimedWait(TimeDelta::Max());
DCHECK(result) << "TimedWait() should never fail with infinite timeout";
}
bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
+ DCHECK_GE(max_time, TimeDelta());
base::ThreadRestrictions::AssertWaitAllowed();
const TimeTicks end_time(TimeTicks::Now() + max_time);
- const bool finite_time = max_time.ToInternalValue() >= 0;
kernel_->lock_.Acquire();
if (kernel_->signaled_) {
@@ -184,7 +184,7 @@ bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
for (;;) {
const TimeTicks current_time(TimeTicks::Now());
- if (sw.fired() || (finite_time && current_time >= end_time)) {
+ if (sw.fired() || current_time >= end_time) {
const bool return_value = sw.fired();
// We can't acquire @lock_ before releasing the SyncWaiter lock (because
@@ -207,12 +207,7 @@ bool WaitableEvent::TimedWait(const TimeDelta& max_time) {
return return_value;
}
- if (finite_time) {
- const TimeDelta max_wait(end_time - current_time);
- sw.cv()->TimedWait(max_wait);
- } else {
- sw.cv()->Wait();
- }
+ sw.cv()->TimedWait(end_time - current_time);
}
}
« 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