Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups for <mutex> etc. #3759

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -762,18 +762,6 @@ private:
}
}

template <class _Predicate>
bool _Wait_until1(unique_lock<mutex>& _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 <class _Clock, class _Duration, class _Predicate>
bool _Wait_until1(
unique_lock<mutex>& _Lck, const chrono::time_point<_Clock, _Duration>& _Abs_time, _Predicate& _Pred) {
Expand Down Expand Up @@ -843,8 +831,12 @@ public:
return try_lock_until(_To_absolute_time(_Rel_time));
}

template <class _Time>
bool _Try_lock_until(_Time _Abs_time) { // try to lock the mutex with timeout
template <class _Clock, class _Duration>
_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<mutex> _Lock(_My_mutex);
if (!_My_cond.wait_until(_Lock, _Abs_time, _UInt_is_zero{_My_locked})) {
return false;
Expand All @@ -854,15 +846,6 @@ public:
return true;
}

template <class _Clock, class _Duration>
_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;
Expand Down Expand Up @@ -944,8 +927,12 @@ public:
return try_lock_until(_To_absolute_time(_Rel_time));
}

template <class _Time>
bool _Try_lock_until(_Time _Abs_time) { // try to lock the mutex with timeout
template <class _Clock, class _Duration>
_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<mutex> _Lock(_My_mutex);
Expand All @@ -967,15 +954,6 @@ public:
return true;
}

template <class _Clock, class _Duration>
_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;
Expand Down
17 changes: 6 additions & 11 deletions stl/inc/shared_mutex
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ public:
return try_lock_shared_until(_To_absolute_time(_Rel_time));
}

template <class _Time>
bool _Try_lock_shared_until(_Time _Abs_time) { // try to lock non-exclusive until absolute time
template <class _Clock, class _Duration>
_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<mutex> _Lock(_Mymtx);
Expand All @@ -180,15 +184,6 @@ public:
return true;
}

template <class _Clock, class _Duration>
_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;
Expand Down