summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsletz <sletz@0c269be4-1314-0410-8aa9-9f06e86f4224>2009-10-23 12:40:54 +0000
committersletz <sletz@0c269be4-1314-0410-8aa9-9f06e86f4224>2009-10-23 12:40:54 +0000
commiteb6d5d16555fb348286fd25836400a56f56dc98e (patch)
treef80c77dace66e7f8fd9eee917117da0dcc14b47f
parent2aab457b5f2b449e6e5e29d8062487b5278e2a89 (diff)
downloadjack2-eb6d5d16555fb348286fd25836400a56f56dc98e.tar.gz
Add new JackBasePosixMutex class.
git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3665 0c269be4-1314-0410-8aa9-9f06e86f4224
-rw-r--r--posix/JackPosixMutex.h41
-rw-r--r--posix/JackProcessSync.h6
2 files changed, 44 insertions, 3 deletions
diff --git a/posix/JackPosixMutex.h b/posix/JackPosixMutex.h
index 8fc6ea06..91d21132 100644
--- a/posix/JackPosixMutex.h
+++ b/posix/JackPosixMutex.h
@@ -33,6 +33,47 @@ namespace Jack
\brief Mutex abstraction.
*/
+
+class JackBasePosixMutex
+{
+
+ protected:
+
+ pthread_mutex_t fMutex;
+
+ public:
+
+ JackBasePosixMutex()
+ {
+ pthread_mutex_init(&fMutex, NULL);
+ }
+
+ virtual ~JackBasePosixMutex()
+ {
+ pthread_mutex_destroy(&fMutex);
+ }
+
+ void Lock()
+ {
+ int res = pthread_mutex_lock(&fMutex);
+ if (res != 0)
+ jack_error("JackBasePosixMutex::Lock res = %d", res);
+ }
+
+ bool Trylock()
+ {
+ return (pthread_mutex_trylock(&fMutex) == 0);
+ }
+
+ void Unlock()
+ {
+ int res = pthread_mutex_unlock(&fMutex);
+ if (res != 0)
+ jack_error("JackBasePosixMutex::Unlock res = %d", res);
+ }
+
+};
+
class JackPosixMutex
{
diff --git a/posix/JackProcessSync.h b/posix/JackProcessSync.h
index 4cf82850..5f45a01e 100644
--- a/posix/JackProcessSync.h
+++ b/posix/JackProcessSync.h
@@ -32,7 +32,7 @@ namespace Jack
\brief A synchronization primitive built using a condition variable.
*/
-class JackProcessSync : public JackPosixMutex
+class JackProcessSync : public JackBasePosixMutex
{
private:
@@ -41,12 +41,12 @@ class JackProcessSync : public JackPosixMutex
public:
- JackProcessSync():JackPosixMutex()
+ JackProcessSync():JackBasePosixMutex()
{
pthread_cond_init(&fCond, NULL);
}
- ~JackProcessSync()
+ virtual ~JackProcessSync()
{
pthread_cond_destroy(&fCond);
}