Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
NullMutex.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_NullMutex_h_
5#define _Stroika_Foundation_Execution_NullMutex_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <mutex>
10
11#include "Stroika/Foundation/Common/Common.h"
12
13/*
14 *
15 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
16 *
17 * @todo see concepts and add static_assert (ILockable - see diff lockable concepts and doc which and enforce wtih statis assert)
18 */
19
21
22 /**
23 * This class follows the Mutex concept - syntactically - but doesn't actually perform locking.
24 *
25 * Sometimes you want to write code that can use locks or not. Use of the NullMutex allows the syntax of
26 * locking to be present, but effectively all compiled (even constexpr) away.
27 */
28 struct NullMutex {
29 constexpr void lock () const
30 {
31 }
32 constexpr bool try_lock () const
33 {
34 return true;
35 }
36 constexpr void unlock () const
37 {
38 }
39 constexpr void lock_shared () const
40 {
41 }
42 constexpr bool try_lock_shared () const
43 {
44 return true;
45 }
46 constexpr void unlock_shared () const
47 {
48 }
49 };
50
51}
52
53/*
54 ********************************************************************************
55 ***************************** Implementation Details ***************************
56 ********************************************************************************
57 */
58#include "NullMutex.inl"
59
60#endif /*_Stroika_Foundation_Execution_NullMutex_h_*/