From: tony.ys_liu Date: Wed, 14 Jan 2015 10:28:03 +0000 (+0800) Subject: Fix false alarm on thread suspend timeout X-Git-Tag: android-x86-7.1-r1~889^2~2205^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=071e48ecfc95b1c67b07c975190d51f646ac4276;p=android-x86%2Fart.git Fix false alarm on thread suspend timeout Root cause: CLOCK_REALTIME will jump backward/forward when system time-of-day clock is changed. It implies now_abs_ts will jump a lot across end_abs_ts. Then, it makes a false alarm (process crash) on thread suspend timeout when doing ComputeRelativeTimeSpec. if (ComputeRelativeTimeSpec(&rel_ts, end_abs_ts, now_abs_ts)) { return false; // Timed out. } Solution: Use CLOCK_MONOTONIC instead Change-Id: I768af52b05ee1548bb291f7d5e2f389ec85e0e71 --- diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index a4eb318d4..17b2ac98c 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -612,7 +612,7 @@ bool ReaderWriterMutex::ExclusiveLockWithTimeout(Thread* self, int64_t ms, int32 #if ART_USE_FUTEXES bool done = false; timespec end_abs_ts; - InitTimeSpec(true, CLOCK_REALTIME, ms, ns, &end_abs_ts); + InitTimeSpec(true, CLOCK_MONOTONIC, ms, ns, &end_abs_ts); do { int32_t cur_state = state_.LoadRelaxed(); if (cur_state == 0) { @@ -621,7 +621,7 @@ bool ReaderWriterMutex::ExclusiveLockWithTimeout(Thread* self, int64_t ms, int32 } else { // Failed to acquire, hang up. timespec now_abs_ts; - InitTimeSpec(true, CLOCK_REALTIME, 0, 0, &now_abs_ts); + InitTimeSpec(true, CLOCK_MONOTONIC, 0, 0, &now_abs_ts); timespec rel_ts; if (ComputeRelativeTimeSpec(&rel_ts, end_abs_ts, now_abs_ts)) { return false; // Timed out.