Botan: src/mutex/noop_mutex/mux_noop.cpp Source File

Botan 1.10.16

mux_noop.cpp
Go to the documentation of this file.
1 /*
2 * No-Op Mutex Factory
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/internal/mux_noop.h>
9
10 namespace Botan {
11
12 /*
13 * No-Op Mutex Factory
14 */
15 Mutex* Noop_Mutex_Factory::make()
16 {
17 class Noop_Mutex : public Mutex
18 {
19 public:
20 class Mutex_State_Error : public Internal_Error
21 {
22 public:
23 Mutex_State_Error(const std::string& where) :
24 Internal_Error("Noop_Mutex::" + where + ": " +
25 "Mutex is already " + where + "ed") {}
26 };
27
28 void lock()
29 {
30 if(locked)
31 throw Mutex_State_Error("lock");
32 locked = true;
33 }
34
35 void unlock()
36 {
37 if(!locked)
38 throw Mutex_State_Error("unlock");
39 locked = false;
40 }
41
42 Noop_Mutex() { locked = false; }
43 private:
44 bool locked;
45 };
46
47 return new Noop_Mutex;
48 }
49
50 }
Botan::Noop_Mutex_Factory::make
Mutex * make()
Definition: mux_noop.cpp:15
Botan::Internal_Error
Definition: exceptn.h:45
Botan
Definition: algo_base.h:14
Botan::Mutex
Definition: mutex.h:18