diff options
Diffstat (limited to 'libcxx/src/condition_variable.cpp')
-rw-r--r-- | libcxx/src/condition_variable.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libcxx/src/condition_variable.cpp b/libcxx/src/condition_variable.cpp index 552bce3561d..de0f6f47dd1 100644 --- a/libcxx/src/condition_variable.cpp +++ b/libcxx/src/condition_variable.cpp @@ -51,10 +51,22 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk, __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked"); nanoseconds d = tp.time_since_epoch(); + if (d > nanoseconds(0x59682F000000E941)) + d = nanoseconds(0x59682F000000E941); timespec ts; seconds s = duration_cast<seconds>(d); - ts.tv_sec = static_cast<decltype(ts.tv_sec)>(s.count()); - ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count()); + typedef decltype(ts.tv_sec) ts_sec; + _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); + if (s.count() < ts_sec_max) + { + ts.tv_sec = static_cast<ts_sec>(s.count()); + ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count()); + } + else + { + ts.tv_sec = ts_sec_max; + ts.tv_nsec = giga::num - 1; + } int ec = pthread_cond_timedwait(&__cv_, lk.mutex()->native_handle(), &ts); if (ec != 0 && ec != ETIMEDOUT) __throw_system_error(ec, "condition_variable timed_wait failed"); |