Add better error checks in mutex support, see https://svn.boost.org/trac/boost/ticket/8903

This commit is contained in:
jzmaddock
2013-12-14 12:58:38 +00:00
parent 956d3c4bcf
commit 7c7f38b009

View File

@ -18,6 +18,7 @@
#define BOOST_REGEX_SOURCE #define BOOST_REGEX_SOURCE
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/assert.hpp>
#ifdef BOOST_HAS_THREADS #ifdef BOOST_HAS_THREADS
@ -54,8 +55,8 @@ void scoped_static_mutex_lock::lock()
{ {
if(0 == m_have_lock) if(0 == m_have_lock)
{ {
pthread_mutex_lock(&(m_mutex.m_mutex)); // Client code will throw if this fails:
m_have_lock = true; m_have_lock = (pthread_mutex_lock(&(m_mutex.m_mutex)) == 0);
} }
} }
@ -63,7 +64,10 @@ void scoped_static_mutex_lock::unlock()
{ {
if(m_have_lock) if(m_have_lock)
{ {
pthread_mutex_unlock(&(m_mutex.m_mutex)); // If this fails there's nothing we can do except assert,
// exceptions are out of the question as this code is called
// from the lock's destructor:
BOOST_VERIFY(pthread_mutex_unlock(&(m_mutex.m_mutex)) == 0);
m_have_lock = false; m_have_lock = false;
} }
} }