Botan 3.13.0
Crypto and TLS for C&
mutex.h
Go to the documentation of this file.
1/*
2* (C) 2016 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_UTIL_MUTEX_H_
8#define BOTAN_UTIL_MUTEX_H_
9
10#include <botan/types.h>
11
12#if defined(BOTAN_TARGET_OS_HAS_THREADS)
13 #include <mutex>
14#endif
15
16namespace Botan {
17
18#if defined(BOTAN_TARGET_OS_HAS_THREADS)
19
20/// The mutex type used by the library
21using mutex_type = std::mutex;
22
23/// The recursive mutex type used by the library
24using recursive_mutex_type = std::recursive_mutex;
25
26template <typename T>
27using lock_guard_type = std::scoped_lock<T>;
28
29#else
30
31// No threads
32
33class noop_mutex final {
34 public:
35 void lock() {}
36
37 void unlock() {}
38};
39
42
43template <typename Mutex>
44class lock_guard final {
45 public:
46 explicit lock_guard(Mutex& m) : m_mutex(m) { m_mutex.lock(); }
47
48 ~lock_guard() { m_mutex.unlock(); }
49
50 lock_guard(const lock_guard& other) = delete;
51 lock_guard& operator=(const lock_guard& other) = delete;
52
53 private:
54 Mutex& m_mutex;
55};
56
57template <typename T>
59
60#endif
61
62} // namespace Botan
63
64#endif
lock_guard(Mutex &m)
Definition mutex.h:46
lock_guard & operator=(const lock_guard &other)=delete
lock_guard(const lock_guard &other)=delete
void lock()
Definition mutex.h:35
void unlock()
Definition mutex.h:37
noop_mutex mutex_type
Definition mutex.h:40
noop_mutex recursive_mutex_type
Definition mutex.h:41
lock_guard< T > lock_guard_type
Definition mutex.h:58