From eb6d5d16555fb348286fd25836400a56f56dc98e Mon Sep 17 00:00:00 2001 From: sletz Date: Fri, 23 Oct 2009 12:40:54 +0000 Subject: [PATCH] Add new JackBasePosixMutex class. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3665 0c269be4-1314-0410-8aa9-9f06e86f4224 --- posix/JackPosixMutex.h | 41 +++++++++++++++++++++++++++++++++++++++++ posix/JackProcessSync.h | 6 +++--- 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); }