Botan: src/mutex/pthreads/mux_pthr.cpp Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 */
22 Mutex* Pthread_Mutex_Factory::make()
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 }
Botan::Invalid_State
Definition: exceptn.h:25
Botan
Definition: algo_base.h:14
Botan::Mutex
Definition: mutex.h:18
Botan::Pthread_Mutex_Factory::make
Mutex * make()
Definition: mux_pthr.cpp:22