Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
TimedLockGuard.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6
7 /*
8 ********************************************************************************
9 ***************************** TimedLockGuard<MUTEX> ****************************
10 ********************************************************************************
11 */
12 template <typename MUTEX>
13 template <typename FAILURE_EXCEPTION>
14 inline TimedLockGuard<MUTEX>::TimedLockGuard (MUTEX& m, const Time::Duration& waitUpTo, const FAILURE_EXCEPTION& timeoutException)
15 : fMutex_ (m)
16 {
17 // timed_mutex::try_lock_for: If timeout_duration is less or equal timeout_duration.zero(), the function behaves like try_lock().
18 // and we want to throw if told to wait negative time...
19 chrono::duration<double> d = waitUpTo.As<chrono::duration<double>> ();
20 if (d <= 0 or not m.try_lock_for ()) {
21 Exeuction::Throw (timeoutException);
22 }
23 }
24 template <typename MUTEX>
26 {
27 fMutex_.unlock ();
28 }
29
30}
TimedLockGuard(MUTEX &m, const Time::Duration &waitUpTo, const FAILURE_EXCEPTION &timeoutException=FAILURE_EXCEPTION{})
Duration is a chrono::duration<double> (=.
Definition Duration.h:96