Skip to content
Snippets Groups Projects
Commit 604a07d9 authored by Eric Cano's avatar Eric Cano
Browse files

Added PTHREAD_MUTEX_ERRORCHECK option to Log mutex, so that mutex misuses get...

Added PTHREAD_MUTEX_ERRORCHECK option to Log mutex, so that mutex misuses get detected (default is blind, undefined behaviour).
parent 50efc4a0
Branches
Tags
No related merge requests found
......@@ -138,12 +138,32 @@ void castor::log::Log::checkProgramNameLen(const std::string &programName)
// initMutex
//------------------------------------------------------------------------------
void castor::log::Log::initMutex() throw(castor::exception::Internal) {
const int rc = pthread_mutex_init(&m_mutex, NULL);
pthread_mutexattr_t attr;
int rc = pthread_mutexattr_init(&attr);
if(0 != rc) {
castor::exception::Internal ex;
ex.getMessage() << "Failed to initialize mutex attribute: " << sstrerror(rc);
throw ex;
}
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
if(0 != rc) {
castor::exception::Internal ex;
ex.getMessage() << "Failed to set mutex type: " << sstrerror(rc);
throw ex;
}
rc = pthread_mutex_init(&m_mutex, NULL);
if(0 != rc) {
castor::exception::Internal ex;
ex.getMessage() << "Failed to initialize m_mutex: " << sstrerror(rc);
throw ex;
}
rc = pthread_mutexattr_destroy(&attr);
if(0 != rc) {
pthread_mutex_destroy(&m_mutex);
castor::exception::Internal ex;
ex.getMessage() << "Failed to destroy mutex attribute: " << sstrerror(rc);
throw ex;
}
}
//------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment