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); }