aboutsummaryrefslogtreecommitdiffstats
path: root/modules/mutex
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 15:34:09 +0000
committerlloyd <[email protected]>2008-09-28 15:34:09 +0000
commitea32d18231b9c6c5c84b3754c4249170d3b4e4c0 (patch)
treecc179337d0594ed105768011722b9dbae105e07a /modules/mutex
parentb841401e095cfc1aa0708689d7920eb95ece71af (diff)
This is the first checkin to net.randombit.botan.modularized, which
has the intent of modularizing Botan's source code, and making it much easier to add or remove various things at compile time. In this first checkin: Add support for nested directories in modules/ and move all the modules into grouped directories like entropy/ or compression/ Currently this is not ideal, it will _only_ find code in modules/*/*/modinfo.txt, while it would be much better to allow for arbitrary nestings under modules (find modules -name modinfo.txt) for more complicated setups. This 'new' (OMG I've found directories!) structure allows for a more free naming convention (no need for leading es_, ml_, etc to group names, though some keep it for lack of a more meaningful name being obvious to me right at the moment).
Diffstat (limited to 'modules/mutex')
-rw-r--r--modules/mutex/pthreads/modinfo.txt29
-rw-r--r--modules/mutex/pthreads/mux_pthr.cpp56
-rw-r--r--modules/mutex/pthreads/mux_pthr.h24
-rw-r--r--modules/mutex/qt_mutex/modinfo.txt18
-rw-r--r--modules/mutex/qt_mutex/mux_qt.cpp33
-rw-r--r--modules/mutex/qt_mutex/mux_qt.h25
-rw-r--r--modules/mutex/win32_crit_section/modinfo.txt16
-rw-r--r--modules/mutex/win32_crit_section/mux_win32.cpp32
-rw-r--r--modules/mutex/win32_crit_section/mux_win32.h24
9 files changed, 257 insertions, 0 deletions
diff --git a/modules/mutex/pthreads/modinfo.txt b/modules/mutex/pthreads/modinfo.txt
new file mode 100644
index 000000000..88de70de0
--- /dev/null
+++ b/modules/mutex/pthreads/modinfo.txt
@@ -0,0 +1,29 @@
+realname "Pthread Mutex"
+
+define MUTEX_PTHREAD
+
+load_on auto
+
+<add>
+mux_pthr.cpp
+mux_pthr.h
+</add>
+
+<libs>
+all!qnx,freebsd,openbsd,netbsd -> pthread
+</libs>
+
+<os>
+aix
+cygwin
+darwin
+freebsd
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>
diff --git a/modules/mutex/pthreads/mux_pthr.cpp b/modules/mutex/pthreads/mux_pthr.cpp
new file mode 100644
index 000000000..d003fa298
--- /dev/null
+++ b/modules/mutex/pthreads/mux_pthr.cpp
@@ -0,0 +1,56 @@
+/*************************************************
+* Pthread Mutex Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_pthr.h>
+#include <botan/exceptn.h>
+
+#ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199506
+#endif
+
+#include <pthread.h>
+
+namespace Botan {
+
+/*************************************************
+* Pthread Mutex Factory *
+*************************************************/
+Mutex* Pthread_Mutex_Factory::make()
+ {
+
+ 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;
+ };
+
+ return new Pthread_Mutex();
+ }
+
+}
diff --git a/modules/mutex/pthreads/mux_pthr.h b/modules/mutex/pthreads/mux_pthr.h
new file mode 100644
index 000000000..1b83dbead
--- /dev/null
+++ b/modules/mutex/pthreads/mux_pthr.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Pthread Mutex Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_EXT_MUTEX_PTHREAD_H__
+#define BOTAN_EXT_MUTEX_PTHREAD_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Pthread Mutex Factory *
+*************************************************/
+class Pthread_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/modules/mutex/qt_mutex/modinfo.txt b/modules/mutex/qt_mutex/modinfo.txt
new file mode 100644
index 000000000..a21108c79
--- /dev/null
+++ b/modules/mutex/qt_mutex/modinfo.txt
@@ -0,0 +1,18 @@
+realname "Qt Mutex"
+
+define MUTEX_QT
+
+note "You'll probably have to add -I/-L flags to the Makefile to find Qt"
+
+load_on request
+
+<add>
+mux_qt.cpp
+mux_qt.h
+</add>
+
+# I think we want to always use qt-mt, not qt -- not much point in supporting
+# mutexes in a single threaded application, after all.
+<libs>
+all -> qt-mt
+</libs>
diff --git a/modules/mutex/qt_mutex/mux_qt.cpp b/modules/mutex/qt_mutex/mux_qt.cpp
new file mode 100644
index 000000000..421b771c7
--- /dev/null
+++ b/modules/mutex/qt_mutex/mux_qt.cpp
@@ -0,0 +1,33 @@
+/*************************************************
+* Qt Thread Mutex Source File *
+* (C) 2004-2007 Justin Karneges *
+* 2004-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_qt.h>
+#include <qmutex.h>
+
+#if !defined(QT_THREAD_SUPPORT)
+ #error Your version of Qt does not support threads or mutexes
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Qt Mutex Factory *
+*************************************************/
+Mutex* Qt_Mutex_Factory::make()
+ {
+ class Qt_Mutex : public Mutex
+ {
+ public:
+ void lock() { mutex.lock(); }
+ void unlock() { mutex.unlock(); }
+ private:
+ QMutex mutex;
+ };
+
+ return new Qt_Mutex();
+ }
+
+}
diff --git a/modules/mutex/qt_mutex/mux_qt.h b/modules/mutex/qt_mutex/mux_qt.h
new file mode 100644
index 000000000..110e147ec
--- /dev/null
+++ b/modules/mutex/qt_mutex/mux_qt.h
@@ -0,0 +1,25 @@
+/*************************************************
+* Qt Mutex Header File *
+* (C) 2004-2007 Justin Karneges *
+* 2004-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_EXT_MUTEX_QT_H__
+#define BOTAN_EXT_MUTEX_QT_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Qt Mutex *
+*************************************************/
+class Qt_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/modules/mutex/win32_crit_section/modinfo.txt b/modules/mutex/win32_crit_section/modinfo.txt
new file mode 100644
index 000000000..d235ff73c
--- /dev/null
+++ b/modules/mutex/win32_crit_section/modinfo.txt
@@ -0,0 +1,16 @@
+realname "Win32 Mutex"
+
+define MUTEX_WIN32
+modset win32
+
+load_on auto
+
+<add>
+mux_win32.cpp
+mux_win32.h
+</add>
+
+<os>
+cygwin
+windows
+</os>
diff --git a/modules/mutex/win32_crit_section/mux_win32.cpp b/modules/mutex/win32_crit_section/mux_win32.cpp
new file mode 100644
index 000000000..622a707fa
--- /dev/null
+++ b/modules/mutex/win32_crit_section/mux_win32.cpp
@@ -0,0 +1,32 @@
+/*************************************************
+* Win32 Mutex Source File *
+* (C) 2006 Luca Piccarreta *
+* 2006-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_win32.h>
+#include <windows.h>
+
+namespace Botan {
+
+/*************************************************
+* Win32 Mutex Factory *
+*************************************************/
+Mutex* Win32_Mutex_Factory::make()
+ {
+ class Win32_Mutex : public Mutex
+ {
+ public:
+ void lock() { EnterCriticalSection(&mutex); }
+ void unlock() { LeaveCriticalSection(&mutex); }
+
+ Win32_Mutex() { InitializeCriticalSection(&mutex); }
+ ~Win32_Mutex() { DeleteCriticalSection(&mutex); }
+ private:
+ CRITICAL_SECTION mutex;
+ };
+
+ return new Win32_Mutex();
+ }
+
+}
diff --git a/modules/mutex/win32_crit_section/mux_win32.h b/modules/mutex/win32_crit_section/mux_win32.h
new file mode 100644
index 000000000..37eadae0d
--- /dev/null
+++ b/modules/mutex/win32_crit_section/mux_win32.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Win32 Mutex Header File *
+* (C) 2006 Luca Piccarreta *
+* 2006-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_EXT_MUTEX_WIN32_H__
+#define BOTAN_EXT_MUTEX_WIN32_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Win32 Mutex Factory *
+*************************************************/
+class Win32_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+}
+
+#endif