Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

rwlock.h
Go to the documentation of this file.
1 /*
2 * (C) 2019 Jack Lloyd
3 *
4 * Botan is released under the Simplified BSD License (see license.txt)
5 */
6
7 #ifndef BOTAN_RWLOCK_H_
8 #define BOTAN_RWLOCK_H_
9
10 #include <botan/types.h>
11 #include <mutex>
12 #include <condition_variable>
13
14 namespace Botan {
15
16 /**
17 * A read-write lock. Writers are favored.
18 */
19 class BOTAN_TEST_API RWLock final
20 {
21 public:
22 RWLock();
23
24 void lock();
25 void unlock();
26
27 void lock_shared();
28 void unlock_shared();
29 private:
30 std::mutex m_mutex;
31 std::condition_variable m_gate1;
32 std::condition_variable m_gate2;
33 uint32_t m_state;
34
35 // 2**31 concurrent readers should be enough for anyone
36 static const uint32_t is_writing = static_cast<uint32_t>(1) << 31;
37 static const uint32_t readers_mask = ~is_writing;
38 };
39
40 }
41
42 #endif
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_TEST_API
#define BOTAN_TEST_API
Definition: compiler.h:45
Botan::RWLock
Definition: rwlock.h:19
m_mutex
mutex_type m_mutex
Definition: oids.cpp:84
Botan
Definition: alg_id.cpp:13
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:72