Commit cf48d6c7 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[base] Don't sample Now() in POSIX's WaitableEvent::Wait()

Fixes a race between sampling Now() on an idle content_unittests helper
thread and ~ScopedTimeClockOverrides. TSAN log:
https://paste.googleplex.com/6136256530481152

Attempt to avoid requiring TSAN suppression @
https://chromium-review.googlesource.com/c/chromium/src/+/1488877

R=kylechar@chromium.org

Bug: 910524
Change-Id: Ida3a3d8fe689a3d51a6f6f6d6870e2dca443f5d1
Reviewed-on: https://chromium-review.googlesource.com/c/1489297Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635615}
parent e5cbb05b
......@@ -200,9 +200,12 @@ bool WaitableEvent::TimedWaitUntil(const TimeTicks& end_time) {
// again before unlocking it.
for (;;) {
const TimeTicks current_time(TimeTicks::Now());
// Only sample Now() if waiting for a |finite_time|.
Optional<TimeTicks> current_time;
if (finite_time)
current_time = TimeTicks::Now();
if (sw.fired() || (finite_time && current_time >= end_time)) {
if (sw.fired() || (finite_time && *current_time >= end_time)) {
const bool return_value = sw.fired();
// We can't acquire @lock_ before releasing the SyncWaiter lock (because
......@@ -226,7 +229,7 @@ bool WaitableEvent::TimedWaitUntil(const TimeTicks& end_time) {
}
if (finite_time) {
const TimeDelta max_wait(end_time - current_time);
const TimeDelta max_wait(end_time - *current_time);
sw.cv()->TimedWait(max_wait);
} else {
sw.cv()->Wait();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment