From 26775afd154ac30ebff963f262799bcd9780bef8 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Sat, 10 Jun 2023 23:39:40 +0800 Subject: [PATCH 1/3] Update 0 --- stl/inc/mutex | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/stl/inc/mutex b/stl/inc/mutex index 68d7cb6d58..8ca319556e 100644 --- a/stl/inc/mutex +++ b/stl/inc/mutex @@ -843,8 +843,12 @@ public: return try_lock_until(_To_absolute_time(_Rel_time)); } - template - bool _Try_lock_until(_Time _Abs_time) { // try to lock the mutex with timeout + template + _NODISCARD_TRY_CHANGE_STATE bool try_lock_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { + // try to lock the mutex with timeout +#if _HAS_CXX20 + static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); +#endif // _HAS_CXX20 unique_lock _Lock(_My_mutex); if (!_My_cond.wait_until(_Lock, _Abs_time, _UInt_is_zero{_My_locked})) { return false; @@ -854,15 +858,6 @@ public: return true; } - template - _NODISCARD_TRY_CHANGE_STATE bool try_lock_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { - // try to lock the mutex with timeout -#if _HAS_CXX20 - static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); -#endif // _HAS_CXX20 - return _Try_lock_until(_Abs_time); - } - private: mutex _My_mutex; condition_variable _My_cond; @@ -944,8 +939,12 @@ public: return try_lock_until(_To_absolute_time(_Rel_time)); } - template - bool _Try_lock_until(_Time _Abs_time) { // try to lock the mutex with timeout + template + _NODISCARD_TRY_CHANGE_STATE bool try_lock_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { + // try to lock the mutex with timeout +#if _HAS_CXX20 + static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); +#endif // _HAS_CXX20 const thread::id _Tid = this_thread::get_id(); unique_lock _Lock(_My_mutex); @@ -967,15 +966,6 @@ public: return true; } - template - _NODISCARD_TRY_CHANGE_STATE bool try_lock_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { - // try to lock the mutex with timeout -#if _HAS_CXX20 - static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); -#endif // _HAS_CXX20 - return _Try_lock_until(_Abs_time); - } - private: mutex _My_mutex; condition_variable _My_cond; From e88a006ca170abf494b8389a7a1d91aba639c3eb Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Sat, 10 Jun 2023 23:51:19 +0800 Subject: [PATCH 2/3] Update 1 --- stl/inc/shared_mutex | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/stl/inc/shared_mutex b/stl/inc/shared_mutex index 824596e26a..dfc004bb0c 100644 --- a/stl/inc/shared_mutex +++ b/stl/inc/shared_mutex @@ -166,8 +166,12 @@ public: return try_lock_shared_until(_To_absolute_time(_Rel_time)); } - template - bool _Try_lock_shared_until(_Time _Abs_time) { // try to lock non-exclusive until absolute time + template + _NODISCARD_TRY_CHANGE_STATE bool try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { + // try to lock non-exclusive until absolute time +#if _HAS_CXX20 + static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); +#endif // _HAS_CXX20 const auto _Can_acquire = [this] { return !_Writing && _Readers < _Max_readers; }; unique_lock _Lock(_Mymtx); @@ -180,15 +184,6 @@ public: return true; } - template - _NODISCARD_TRY_CHANGE_STATE bool try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& _Abs_time) { - // try to lock non-exclusive until absolute time -#if _HAS_CXX20 - static_assert(chrono::is_clock_v<_Clock>, "Clock type required"); -#endif // _HAS_CXX20 - return _Try_lock_shared_until(_Abs_time); - } - void unlock_shared() { // unlock non-exclusive _Read_cnt_t _Local_readers; bool _Local_writing; From 13aec12ff32de46a5865d214631b8fe07eae98c3 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Sat, 10 Jun 2023 23:59:16 +0800 Subject: [PATCH 3/3] Update 2 --- stl/inc/mutex | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stl/inc/mutex b/stl/inc/mutex index 8ca319556e..df95413a25 100644 --- a/stl/inc/mutex +++ b/stl/inc/mutex @@ -762,18 +762,6 @@ private: } } - template - bool _Wait_until1(unique_lock& _Lck, const _timespec64* _Abs_time, _Predicate& _Pred) { - // wait for signal with timeout and check predicate - while (!_Pred()) { - if (_Wait_until_sys_time(_Lck, _Abs_time) == cv_status::timeout) { - return _Pred(); - } - } - - return true; - } - template bool _Wait_until1( unique_lock& _Lck, const chrono::time_point<_Clock, _Duration>& _Abs_time, _Predicate& _Pred) {