dol: initial dol commit
[jump.git] / dol / src / dol / visitor / PipeAndFilter / lib / Mutex.cpp
diff --git a/dol/src/dol/visitor/PipeAndFilter/lib/Mutex.cpp b/dol/src/dol/visitor/PipeAndFilter/lib/Mutex.cpp
new file mode 100644 (file)
index 0000000..b943ff3
--- /dev/null
@@ -0,0 +1,48 @@
+#include "Mutex.h"\r
+\r
+Mutex::Mutex() {\r
+    //std::cout << "Create Mutex." << std::endl;\r
+    _mutex = new pthread_mutex_t;\r
+    pthread_mutex_init(_mutex, NULL); //_mutexAttribute);\r
+\r
+    _localMutex = new pthread_mutex_t;\r
+    pthread_mutex_init(_localMutex, NULL);\r
+\r
+    _lockCondition = new pthread_cond_t;\r
+    pthread_cond_init(_lockCondition, NULL);\r
+}\r
+\r
+\r
+Mutex::~Mutex() {\r
+    //std::cout << "Delete Mutex." << std::endl;\r
+    pthread_mutex_destroy(_mutex);\r
+    delete _mutex;\r
+\r
+    pthread_mutex_destroy(_localMutex);\r
+    delete _localMutex;\r
+\r
+    pthread_cond_destroy(_lockCondition);\r
+    delete _lockCondition;\r
+    //std::cout << "Deleted Mutex." << std::endl;\r
+}\r
+\r
+\r
+int Mutex::trylock() {\r
+    int success = pthread_mutex_trylock(_mutex);\r
+    return success;\r
+}\r
+\r
+\r
+void Mutex::lock() {\r
+    pthread_mutex_lock(_mutex);\r
+}\r
+\r
+\r
+void Mutex::unlock() {\r
+    pthread_mutex_unlock(_mutex);\r
+}\r
+\r
+\r
+pthread_mutex_t *Mutex::getPThreadMutex() const {\r
+    return _mutex;\r
+}\r