Botan  1.10.9
mux_pthr.cpp
Go to the documentation of this file.
1 /*
2 * Pthread Mutex
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/internal/mux_pthr.h>
9 #include <botan/exceptn.h>
10 
11 #ifndef _POSIX_C_SOURCE
12  #define _POSIX_C_SOURCE 199506
13 #endif
14 
15 #include <pthread.h>
16 
17 namespace Botan {
18 
19 /*
20 * Pthread Mutex Factory
21 */
23  {
24 
25  class Pthread_Mutex : public Mutex
26  {
27  public:
28  void lock()
29  {
30  if(pthread_mutex_lock(&mutex) != 0)
31  throw Invalid_State("Pthread_Mutex::lock: Error occured");
32  }
33 
34  void unlock()
35  {
36  if(pthread_mutex_unlock(&mutex) != 0)
37  throw Invalid_State("Pthread_Mutex::unlock: Error occured");
38  }
39 
40  Pthread_Mutex()
41  {
42  if(pthread_mutex_init(&mutex, 0) != 0)
43  throw Invalid_State("Pthread_Mutex: initialization failed");
44  }
45 
46  ~Pthread_Mutex()
47  {
48  if(pthread_mutex_destroy(&mutex) != 0)
49  throw Invalid_State("~Pthread_Mutex: mutex is still locked");
50  }
51  private:
52  pthread_mutex_t mutex;
53  };
54 
55  return new Pthread_Mutex();
56  }
57 
58 }
Mutex * mutex
Definition: global_rng.cpp:164