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