Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__mutex_base
Show First 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | template <class _Rep, class _Period, class _Predicate> | ||||
_Predicate __pred); | _Predicate __pred); | ||||
typedef __libcpp_condvar_t* native_handle_type; | typedef __libcpp_condvar_t* native_handle_type; | ||||
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;} | _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;} | ||||
private: | private: | ||||
void __do_timed_wait(unique_lock<mutex>& __lk, | void __do_timed_wait(unique_lock<mutex>& __lk, | ||||
chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT; | chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT; | ||||
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT) | #if defined(_LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT) | ||||
void __do_timed_wait(unique_lock<mutex>& __lk, | void __do_timed_wait(unique_lock<mutex>& __lk, | ||||
chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT; | chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT; | ||||
#endif | #endif | ||||
template <class _Clock> | template <class _Clock> | ||||
void __do_timed_wait(unique_lock<mutex>& __lk, | void __do_timed_wait(unique_lock<mutex>& __lk, | ||||
chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT; | chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT; | ||||
}; | }; | ||||
#endif // !_LIBCPP_HAS_NO_THREADS | #endif // !_LIBCPP_HAS_NO_THREADS | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | condition_variable::wait_for(unique_lock<mutex>& __lk, | ||||
const chrono::duration<_Rep, _Period>& __d) | const chrono::duration<_Rep, _Period>& __d) | ||||
{ | { | ||||
using namespace chrono; | using namespace chrono; | ||||
if (__d <= __d.zero()) | if (__d <= __d.zero()) | ||||
return cv_status::timeout; | return cv_status::timeout; | ||||
using __ns_rep = nanoseconds::rep; | using __ns_rep = nanoseconds::rep; | ||||
steady_clock::time_point __c_now = steady_clock::now(); | steady_clock::time_point __c_now = steady_clock::now(); | ||||
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT) | #if defined(_LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT) | ||||
using __clock_tp_ns = time_point<steady_clock, nanoseconds>; | using __clock_tp_ns = time_point<steady_clock, nanoseconds>; | ||||
__ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(__c_now.time_since_epoch()).count(); | __ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(__c_now.time_since_epoch()).count(); | ||||
#else | #else | ||||
using __clock_tp_ns = time_point<system_clock, nanoseconds>; | using __clock_tp_ns = time_point<system_clock, nanoseconds>; | ||||
__ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count(); | __ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count(); | ||||
#endif | #endif | ||||
__ns_rep __d_ns_count = _VSTD::__safe_nanosecond_cast(__d).count(); | __ns_rep __d_ns_count = _VSTD::__safe_nanosecond_cast(__d).count(); | ||||
Show All 14 Lines | |||||
condition_variable::wait_for(unique_lock<mutex>& __lk, | condition_variable::wait_for(unique_lock<mutex>& __lk, | ||||
const chrono::duration<_Rep, _Period>& __d, | const chrono::duration<_Rep, _Period>& __d, | ||||
_Predicate __pred) | _Predicate __pred) | ||||
{ | { | ||||
return wait_until(__lk, chrono::steady_clock::now() + __d, | return wait_until(__lk, chrono::steady_clock::now() + __d, | ||||
_VSTD::move(__pred)); | _VSTD::move(__pred)); | ||||
} | } | ||||
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT) | #if defined(_LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT) | ||||
inline | inline | ||||
void | void | ||||
condition_variable::__do_timed_wait(unique_lock<mutex>& __lk, | condition_variable::__do_timed_wait(unique_lock<mutex>& __lk, | ||||
chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT | chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT | ||||
{ | { | ||||
using namespace chrono; | using namespace chrono; | ||||
if (!__lk.owns_lock()) | if (!__lk.owns_lock()) | ||||
__throw_system_error(EPERM, | __throw_system_error(EPERM, | ||||
"condition_variable::timed wait: mutex not locked"); | "condition_variable::timed wait: mutex not locked"); | ||||
nanoseconds __d = __tp.time_since_epoch(); | nanoseconds __d = __tp.time_since_epoch(); | ||||
timespec __ts; | __libcpp_timespec_t __ts; | ||||
seconds __s = duration_cast<seconds>(__d); | seconds __s = duration_cast<seconds>(__d); | ||||
using __ts_sec = decltype(__ts.tv_sec); | using __ts_sec = decltype(__ts.tv_sec); | ||||
const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); | const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max(); | ||||
if (__s.count() < __ts_sec_max) | if (__s.count() < __ts_sec_max) | ||||
{ | { | ||||
__ts.tv_sec = static_cast<__ts_sec>(__s.count()); | __ts.tv_sec = static_cast<__ts_sec>(__s.count()); | ||||
__ts.tv_nsec = (__d - __s).count(); | __ts.tv_nsec = (__d - __s).count(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
__ts.tv_sec = __ts_sec_max; | __ts.tv_sec = __ts_sec_max; | ||||
__ts.tv_nsec = giga::num - 1; | __ts.tv_nsec = giga::num - 1; | ||||
} | } | ||||
int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts); | int __ec = __libcpp_condvar_monotonic_timedwait(&__cv_, | ||||
__lk.mutex()->native_handle(), | |||||
&__ts); | |||||
if (__ec != 0 && __ec != ETIMEDOUT) | if (__ec != 0 && __ec != ETIMEDOUT) | ||||
__throw_system_error(__ec, "condition_variable timed_wait failed"); | __throw_system_error(__ec, "condition_variable timed_wait failed"); | ||||
} | } | ||||
#endif // _LIBCPP_HAS_COND_CLOCKWAIT | #endif // _LIBCPP_CONDVAR_HAS_MONOTONIC_TIMEDWAIT | ||||
template <class _Clock> | template <class _Clock> | ||||
inline | inline | ||||
void | void | ||||
condition_variable::__do_timed_wait(unique_lock<mutex>& __lk, | condition_variable::__do_timed_wait(unique_lock<mutex>& __lk, | ||||
chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT | chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT | ||||
{ | { | ||||
wait_for(__lk, __tp - _Clock::now()); | wait_for(__lk, __tp - _Clock::now()); | ||||
Show All 9 Lines |