Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/boost/interprocess/sync/posix/pthread_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ namespace ipcdetail{
if(pthread_mutexattr_init(&m_attr)!=0 ||
pthread_mutexattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED)!= 0 ||
(recursive &&
pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE)!= 0 ))
throw interprocess_exception("pthread_mutexattr_xxxx failed");
pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE) != 0 ) ||
pthread_mutexattr_setrobust(&m_attr, PTHREAD_MUTEX_ROBUST) != 0 )
throw interprocess_exception("pthread_mutexattr_xxxx failed");
}

//!Destructor
Expand Down
28 changes: 22 additions & 6 deletions include/boost/interprocess/sync/posix/recursive_mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,27 @@ inline posix_recursive_mutex::~posix_recursive_mutex()

inline void posix_recursive_mutex::lock()
{
if (pthread_mutex_lock(&m_mut) != 0)
int res = pthread_mutex_lock(&m_mut);
if (res == EOWNERDEAD)
{
pthread_mutex_consistent(&m_mut);
throw interprocess_exception(owner_dead_error);
}
else if (res != 0)
throw lock_exception();
}

inline bool posix_recursive_mutex::try_lock()
{
int res = pthread_mutex_trylock(&m_mut);
if (!(res == 0 || res == EBUSY))
if (res == EOWNERDEAD)
{
pthread_mutex_consistent(&m_mut);
throw interprocess_exception(owner_dead_error);
}
else if (!(res == 0 || res == EBUSY))
throw lock_exception();
return res == 0;
return (res == 0);
}

inline bool posix_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
Expand All @@ -110,9 +121,14 @@ inline bool posix_recursive_mutex::timed_lock(const boost::posix_time::ptime &ab

timespec ts = ptime_to_timespec(abs_time);
int res = pthread_mutex_timedlock(&m_mut, &ts);
if (res != 0 && res != ETIMEDOUT)
throw lock_exception();
return res == 0;
if (res == EOWNERDEAD)
{
pthread_mutex_consistent(&m_mut);
throw interprocess_exception(owner_dead_error);
}
else if (res != 0 && res != ETIMEDOUT)
throw lock_exception();
return (res == 0);

#else //BOOST_INTERPROCESS_POSIX_TIMEOUTS

Expand Down