Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
TimedLock.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
5
7
8 /*
9 ********************************************************************************
10 ************************* Execution::TryLockUntil ******************************
11 ********************************************************************************
12 */
13 template <Common::StdCompat::TimedMutex TIMED_MUTEX, typename EXCEPTION>
14 inline void TryLockUntil (TIMED_MUTEX& m, Time::TimePointSeconds afterTickCount, EXCEPTION&& exception2Throw)
15 {
16 if (not m.try_lock_until (Time::Pin2SafeSeconds (afterTickCount))) {
17 Throw (forward<EXCEPTION> (exception2Throw));
18 }
19 }
20 template <Common::StdCompat::TimedMutex TIMED_MUTEX>
21 inline void TryLockUntil (TIMED_MUTEX& m, Time::TimePointSeconds afterTickCount)
22 {
23 if (not m.try_lock_until (Time::Pin2SafeSeconds (afterTickCount))) {
24 ThrowError (errc::timed_out);
25 }
26 }
27
28 /*
29 ********************************************************************************
30 ***************************** Execution::UniqueLock ****************************
31 ********************************************************************************
32 */
33 template <Common::StdCompat::TimedMutex TIMED_MUTEX, typename EXCEPTION>
34 inline unique_lock<TIMED_MUTEX> UniqueLock (TIMED_MUTEX& m, const chrono::duration<double>& d, EXCEPTION&& exception2Throw)
35 {
36 unique_lock<TIMED_MUTEX> lock{m, d};
37 if (not lock.owns_lock ()) {
38 Throw (forward<EXCEPTION> (exception2Throw));
39 }
40 return lock;
41 }
42 template <Common::StdCompat::TimedMutex TIMED_MUTEX>
43 inline unique_lock<TIMED_MUTEX> UniqueLock (TIMED_MUTEX& m, const chrono::duration<double>& d)
44 {
45 unique_lock<TIMED_MUTEX> lock{m, d};
46 if (not lock.owns_lock ()) {
47 ThrowError (errc::timed_out);
48 }
49 return lock;
50 }
51
52}
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Definition Realtime.h:82
unique_lock< TIMED_MUTEX > UniqueLock(TIMED_MUTEX &m, const chrono::duration< double > &d, EXCEPTION &&exception2Throw)
Definition TimedLock.inl:34
void Throw(T &&e2Throw)
like the builtin C++ 'throw', but stamps in the current Activity context and does helpful,...
Definition Throw.inl:54
void TryLockUntil(TIMED_MUTEX &m, Time::TimePointSeconds afterTickCount, EXCEPTION &&exception2Throw)
Definition TimedLock.inl:14
void ThrowError(error_code ec)
throw a SystemErrorException with the given error_code - or std::bad_alloc for errc::not_enough_memor...