Botan: src/mutex/mutex.h Source File

Botan 1.10.17

mutex.h
Go to the documentation of this file.
1 /*
2 * Mutex
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_MUTEX_H__
9 #define BOTAN_MUTEX_H__
10
11 #include <botan/exceptn.h>
12
13 namespace Botan {
14
15 /**
16 * Mutex Base Class
17 */
18 class Mutex
19 {
20 public:
21 /**
22 * Lock the mutex
23 */
24 virtual void lock() = 0;
25
26 /**
27 * Unlock the mutex
28 */
29 virtual void unlock() = 0;
30 virtual ~Mutex() {}
31 };
32
33 /**
34 * Mutex Factory
35 */
36 class Mutex_Factory
37 {
38 public:
39 /**
40 * @return newly allocated mutex
41 */
42 virtual Mutex* make() = 0;
43
44 virtual ~Mutex_Factory() {}
45 };
46
47 /**
48 * Mutex Holding Class for RAII
49 */
50 class Mutex_Holder
51 {
52 public:
53 /**
54 * Hold onto a mutex until we leave scope
55 * @param m the mutex to lock
56 */
57 Mutex_Holder(Mutex* m) : mux(m)
58 {
59 if(!mux)
60 throw Invalid_Argument("Mutex_Holder: Argument was NULL");
61 mux->lock();
62 }
63
64 ~Mutex_Holder() { mux->unlock(); }
65 private:
66 Mutex* mux;
67 };
68
69 }
70
71 #endif
Botan::Mutex_Holder::~Mutex_Holder
~Mutex_Holder()
Definition: mutex.h:64
Botan::Mutex::~Mutex
virtual ~Mutex()
Definition: mutex.h:30
Botan::Mutex_Factory
Definition: mutex.h:36
Botan::Mutex::lock
virtual void lock()=0
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::Mutex::unlock
virtual void unlock()=0
Botan::Mutex_Factory::make
virtual Mutex * make()=0
Botan
Definition: algo_base.h:14
Botan::Mutex_Holder::Mutex_Holder
Mutex_Holder(Mutex *m)
Definition: mutex.h:57
Botan::Mutex
Definition: mutex.h:18
Botan::Mutex_Holder
Definition: mutex.h:50
Botan::Mutex_Factory::~Mutex_Factory
virtual ~Mutex_Factory()
Definition: mutex.h:44