/* * MutexedClass.cpp * * Created on: Feb 15, 2015 * Author: hovanes */ #include "MutexedClass.hh" //! Declare global mutex and its attributes pthread_mutex_t MutexedClass::mcClassMutex; pthread_mutexattr_t MutexedClass::mcClassMtxAttr; // Initialize global mutexes and the attributes volatile static int dummyInt = MutexedClass::initGlobalMutex(); MutexedClass::MutexedClass() { initMutex(); return; } MutexedClass::~MutexedClass() { closeMutex(); return; } // Mutex manipulation functions //! Initialize global mutex int MutexedClass::initGlobalMutex() { pthread_mutexattr_init( &mcClassMtxAttr ); pthread_mutexattr_setpshared( &mcClassMtxAttr, PTHREAD_PROCESS_PRIVATE ); pthread_mutex_init( &mcClassMutex, &mcClassMtxAttr ); return 0; } //! Initialize mutex for individual objects void MutexedClass::initMutex() { pthread_mutexattr_init( &mcMtxAttr ); pthread_mutexattr_setpshared( &mcMtxAttr, PTHREAD_PROCESS_PRIVATE ); pthread_mutex_init( &mcMutex, &mcMtxAttr ); return; } //! Destroy mutex for individual objects void MutexedClass::closeMutex() { pthread_mutex_destroy( &mcMutex ); pthread_mutexattr_destroy( &mcMtxAttr ); return; }