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

Unified Diff: src/futex-emulation.cc

Issue 1272733002: [futex] Avoid accumulation errors in futex wait timeout (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/futex-emulation.cc
diff --git a/src/futex-emulation.cc b/src/futex-emulation.cc
index b8168a87045f55c0e11dd75d4b4bb4ba0de18cdd..39f43dd7dd8c998e8ec571b5942194827a240f75 100644
--- a/src/futex-emulation.cc
+++ b/src/futex-emulation.cc
@@ -101,18 +101,25 @@ Object* FutexEmulation::Wait(Isolate* isolate,
}
}
- base::TimeDelta rel_time_left = rel_timeout;
+ base::Time start_time = base::Time::NowFromSystemTime();
+ base::Time timeout_time = start_time + rel_timeout;
wait_list_.Pointer()->AddNode(node);
Object* result;
while (true) {
- base::TimeDelta time_to_wait = (use_timeout && rel_time_left < kMaxWaitTime)
- ? rel_time_left
- : kMaxWaitTime;
+ base::Time current_time = base::Time::NowFromSystemTime();
+ if (use_timeout && current_time > timeout_time) {
+ result = Smi::FromInt(Result::kTimedOut);
+ break;
+ }
+
+ base::TimeDelta time_until_timeout = timeout_time - current_time;
+ base::TimeDelta time_to_wait =
+ (use_timeout && time_until_timeout < kMaxWaitTime) ? time_until_timeout
+ : kMaxWaitTime;
- base::Time start_time = base::Time::NowFromSystemTime();
bool wait_for_result = node->cond_.WaitFor(mutex_.Pointer(), time_to_wait);
USE(wait_for_result);
@@ -121,17 +128,8 @@ Object* FutexEmulation::Wait(Isolate* isolate,
break;
}
- // Spurious wakeup or timeout.
- base::Time end_time = base::Time::NowFromSystemTime();
- base::TimeDelta waited_for = end_time - start_time;
- rel_time_left -= waited_for;
-
- if (use_timeout && rel_time_left < base::TimeDelta::FromMicroseconds(0)) {
- result = Smi::FromInt(Result::kTimedOut);
- break;
- }
-
- // Potentially handle interrupts before continuing to wait.
+ // Spurious wakeup or timeout. Potentially handle interrupts before
+ // continuing to wait.
Object* interrupt_object = isolate->stack_guard()->HandleInterrupts();
if (interrupt_object->IsException()) {
result = interrupt_object;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698