Botan  1.10.9
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 */
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 */
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
virtual ~Mutex()
Definition: mutex.h:30
virtual void lock()=0
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
virtual void unlock()=0
virtual Mutex * make()=0
Mutex_Holder(Mutex *m)
Definition: mutex.h:57
virtual ~Mutex_Factory()
Definition: mutex.h:44