@@ -25,6 +25,18 @@ | |||||
namespace Jack | namespace Jack | ||||
{ | { | ||||
JackBasePosixMutex::JackBasePosixMutex(const char* name) | |||||
:fOwner(0) | |||||
{ | |||||
int res = pthread_mutex_init(&fMutex, NULL); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex")); | |||||
} | |||||
JackBasePosixMutex::~JackBasePosixMutex() | |||||
{ | |||||
pthread_mutex_destroy(&fMutex); | |||||
} | |||||
bool JackBasePosixMutex::Lock() | bool JackBasePosixMutex::Lock() | ||||
{ | { | ||||
pthread_t current_thread = pthread_self(); | pthread_t current_thread = pthread_self(); | ||||
@@ -79,6 +91,25 @@ namespace Jack | |||||
} | } | ||||
} | } | ||||
JackPosixMutex::JackPosixMutex(const char* name) | |||||
{ | |||||
// Use recursive mutex | |||||
pthread_mutexattr_t mutex_attr; | |||||
int res; | |||||
res = pthread_mutexattr_init(&mutex_attr); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex attribute")); | |||||
res = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not settype the mutex")); | |||||
res = pthread_mutex_init(&fMutex, &mutex_attr); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex")); | |||||
pthread_mutexattr_destroy(&mutex_attr); | |||||
} | |||||
JackPosixMutex::~JackPosixMutex() | |||||
{ | |||||
pthread_mutex_destroy(&fMutex); | |||||
} | |||||
bool JackPosixMutex::Lock() | bool JackPosixMutex::Lock() | ||||
{ | { | ||||
int res = pthread_mutex_lock(&fMutex); | int res = pthread_mutex_lock(&fMutex); | ||||
@@ -45,16 +45,8 @@ class SERVER_EXPORT JackBasePosixMutex | |||||
public: | public: | ||||
JackBasePosixMutex(const char* name = NULL):fOwner(0) | |||||
{ | |||||
int res = pthread_mutex_init(&fMutex, NULL); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex")); | |||||
} | |||||
virtual ~JackBasePosixMutex() | |||||
{ | |||||
pthread_mutex_destroy(&fMutex); | |||||
} | |||||
JackBasePosixMutex(const char* name = NULL); | |||||
virtual ~JackBasePosixMutex(); | |||||
bool Lock(); | bool Lock(); | ||||
bool Trylock(); | bool Trylock(); | ||||
@@ -70,31 +62,14 @@ class SERVER_EXPORT JackPosixMutex | |||||
public: | public: | ||||
JackPosixMutex(const char* name = NULL) | |||||
{ | |||||
// Use recursive mutex | |||||
pthread_mutexattr_t mutex_attr; | |||||
int res; | |||||
res = pthread_mutexattr_init(&mutex_attr); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex attribute")); | |||||
res = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not settype the mutex")); | |||||
res = pthread_mutex_init(&fMutex, &mutex_attr); | |||||
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex")); | |||||
pthread_mutexattr_destroy(&mutex_attr); | |||||
} | |||||
virtual ~JackPosixMutex() | |||||
{ | |||||
pthread_mutex_destroy(&fMutex); | |||||
} | |||||
JackPosixMutex(const char* name = NULL); | |||||
virtual ~JackPosixMutex(); | |||||
bool Lock(); | bool Lock(); | ||||
bool Trylock(); | bool Trylock(); | ||||
bool Unlock(); | bool Unlock(); | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
#endif | #endif |
@@ -90,12 +90,12 @@ class JackWinCondVar { | |||||
DeleteCriticalSection(&fMutex); | DeleteCriticalSection(&fMutex); | ||||
} | } | ||||
bool TimedWait(long usec); | |||||
bool TimedWait(long usec) | |||||
{ | { | ||||
return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000); | return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000); | ||||
} | } | ||||
bool LockedTimedWait(long usec); | |||||
bool LockedTimedWait(long usec) | |||||
{ | { | ||||
EnterCriticalSection(&fMutex); | EnterCriticalSection(&fMutex); | ||||
return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000); | return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000); | ||||