From a2c99d3270eb73ef2db5704fc54356c6b75096f8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 18 May 2006 18:33:19 +0000 Subject: Initial checkin --- modules/mux_pthr/mux_pthr.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 modules/mux_pthr/mux_pthr.cpp (limited to 'modules/mux_pthr/mux_pthr.cpp') diff --git a/modules/mux_pthr/mux_pthr.cpp b/modules/mux_pthr/mux_pthr.cpp new file mode 100644 index 000000000..ec2308fae --- /dev/null +++ b/modules/mux_pthr/mux_pthr.cpp @@ -0,0 +1,62 @@ +/************************************************* +* Pthread Mutex Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include + +namespace Botan { + +namespace { + +/************************************************* +* Pthread Mutex * +*************************************************/ +class Pthread_Mutex : public Mutex + { + public: + void lock() + { + if(pthread_mutex_lock(&mutex) != 0) + throw Exception("Pthread_Mutex::lock: Error occured"); + } + + void unlock() + { + if(pthread_mutex_unlock(&mutex) != 0) + throw Exception("Pthread_Mutex::unlock: Error occured"); + } + + Pthread_Mutex() + { + if(pthread_mutex_init(&mutex, 0) != 0) + throw Exception("Pthread_Mutex: initialization failed"); + } + + ~Pthread_Mutex() + { + if(pthread_mutex_destroy(&mutex) != 0) + throw Invalid_State("~Pthread_Mutex: mutex is still locked"); + } + private: + pthread_mutex_t mutex; + }; + +} + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +Mutex* Pthread_Mutex_Factory::make() + { + return new Pthread_Mutex(); + } + +} -- cgit v1.2.3