Botan 3.2.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
14 #include <mutex>
15
16namespace Botan {
17
18template <typename T>
19using lock_guard_type = std::lock_guard<T>;
20using mutex_type = std::mutex;
21using recursive_mutex_type = std::recursive_mutex;
22
23} // namespace Botan
24
25#else
26
27// No threads
28
29namespace Botan {
30
31template <typename Mutex>
33 public:
34 explicit lock_guard(Mutex& m) : m_mutex(m) { m_mutex.lock(); }
35
36 ~lock_guard() { m_mutex.unlock(); }
37
38 lock_guard(const lock_guard& other) = delete;
39 lock_guard& operator=(const lock_guard& other) = delete;
40
41 private:
42 Mutex& m_mutex;
43};
44
46 public:
47 void lock() {}
48
49 void unlock() {}
50};
51
54template <typename T>
56
57} // namespace Botan
58
59#endif
60
61#endif
lock_guard(Mutex &m)
Definition mutex.h:34
lock_guard & operator=(const lock_guard &other)=delete
lock_guard(const lock_guard &other)=delete
void lock()
Definition mutex.h:47
void unlock()
Definition mutex.h:49
int(* final)(unsigned char *, CTX *)
lock_guard< T > lock_guard_type
Definition mutex.h:55
noop_mutex recursive_mutex_type
Definition mutex.h:53
noop_mutex mutex_type
Definition mutex.h:52