Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
TimedLockGuard.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_TimedLockGuard_h_
5#define _Stroika_Foundation_Execution_TimedLockGuard_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <mutex>
10
11#include "Stroika/Foundation/Execution/TimeOutException.h"
13
15
16 /**
17 * Like lock_guard, but only used on TIMED mutexes, and instead of unique_lock::try_lock() returning false
18 * or the CTOR just silently failing to lock, this throws a lock failure.
19 *
20 * \see also UniqueLock
21 */
22 template <typename MUTEX = timed_mutex>
24 public:
25 /**
26 * \note if argument duration is <= 0, this always throws regardless if whether or not the mutex could be acquired.
27 */
28 template <typename FAILURE_EXCEPTION = TimeOutException>
29 TimedLockGuard (MUTEX& m, const Time::Duration& waitUpTo, const FAILURE_EXCEPTION& timeoutException = FAILURE_EXCEPTION{});
30 TimedLockGuard (const TimedLockGuard&) = delete;
31 TimedLockGuard& operator= (const TimedLockGuard&) = delete;
33
34 private:
35 MUTEX& fMutex_;
36 };
37
38}
39
40/*
41 ********************************************************************************
42 ***************************** Implementation Details ***************************
43 ********************************************************************************
44 */
45#include "TimedLockGuard.inl"
46
47#endif /*_Stroika_Foundation_Execution_TimedLockGuard_h_*/
Duration is a chrono::duration<double> (=.
Definition Duration.h:96