Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84540 - in trunk: boost/thread/pthread libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons
From: vicente.botet_at_[hidden]
Date: 2013-05-28 16:06:52


Author: viboes
Date: 2013-05-28 16:06:51 EDT (Tue, 28 May 2013)
New Revision: 84540
URL: http://svn.boost.org/trac/boost/changeset/84540

Log:
Thread: Reintroduce BOOST_VERIFY on pthread_mutex_destroy return type #8626.
Text files modified:
   trunk/boost/thread/pthread/mutex.hpp | 90 +++++++++++++++++++++++++++------------
   trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp | 1
   trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp | 1
   3 files changed, 61 insertions(+), 31 deletions(-)

Modified: trunk/boost/thread/pthread/mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/mutex.hpp (original)
+++ trunk/boost/thread/pthread/mutex.hpp 2013-05-28 16:06:51 EDT (Tue, 28 May 2013)
@@ -33,10 +33,61 @@
 #endif
 #endif
 
+
 #include <boost/config/abi_prefix.hpp>
 
+#ifndef BOOST_THREAD_HAS_NO_EINTR_BUG
+#define BOOST_THREAD_HAS_EINTR_BUG
+#endif
+
 namespace boost
 {
+ namespace posix {
+#ifdef BOOST_THREAD_HAS_EINTR_BUG
+ BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
+ {
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_destroy(m);
+ } while (ret == EINTR);
+ return ret;
+ }
+ BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
+ {
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_lock(m);
+ } while (ret == EINTR);
+ return ret;
+ }
+ BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
+ {
+ int ret;
+ do
+ {
+ ret = ::pthread_mutex_unlock(m);
+ } while (ret == EINTR);
+ return ret;
+ }
+#else
+ BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
+ {
+ return ::pthread_mutex_destroy(m);
+ }
+ BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
+ {
+ return ::pthread_mutex_lock(m);
+ }
+ BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
+ {
+ return ::pthread_mutex_unlock(m);
+ }
+
+#endif
+
+ }
     class mutex
     {
     private:
@@ -54,20 +105,12 @@
         }
         ~mutex()
         {
- int ret;
- do
- {
- ret = pthread_mutex_destroy(&m);
- } while (ret == EINTR);
+ BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
         }
 
         void lock()
         {
- int res;
- do
- {
- res = pthread_mutex_lock(&m);
- } while (res == EINTR);
+ int res = posix::pthread_mutex_lock(&m);
             if (res)
             {
                 boost::throw_exception(lock_error(res,"boost: mutex lock failed in pthread_mutex_lock"));
@@ -76,14 +119,10 @@
 
         void unlock()
         {
- int res;
- do
- {
- res = pthread_mutex_unlock(&m);
- } while (res == EINTR);
+ int res = posix::pthread_mutex_unlock(&m);
             if (res)
             {
- boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_lock"));
+ boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_unlock"));
             }
         }
 
@@ -138,7 +177,8 @@
             int const res2=pthread_cond_init(&cond,NULL);
             if(res2)
             {
- BOOST_VERIFY(!pthread_mutex_destroy(&m));
+ BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
+ //BOOST_VERIFY(!pthread_mutex_destroy(&m));
                 boost::throw_exception(thread_resource_error(res2, "boost:: timed_mutex constructor failed in pthread_cond_init"));
             }
             is_locked=false;
@@ -146,7 +186,7 @@
         }
         ~timed_mutex()
         {
- BOOST_VERIFY(!pthread_mutex_destroy(&m));
+ BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
 #ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
             BOOST_VERIFY(!pthread_cond_destroy(&cond));
 #endif
@@ -166,11 +206,7 @@
 #ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
         void lock()
         {
- int res;
- do
- {
- res = pthread_mutex_lock(&m);
- } while (res == EINTR);
+ int res = posix::pthread_mutex_lock(&m);
             if (res)
             {
                 boost::throw_exception(lock_error(res,"boost: mutex lock failed in pthread_mutex_lock"));
@@ -179,14 +215,10 @@
 
         void unlock()
         {
- int res;
- do
- {
- res = pthread_mutex_unlock(&m);
- } while (res == EINTR);
+ int res = posix::pthread_mutex_unlock(&m);
             if (res)
             {
- boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_lock"));
+ boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_unlock"));
             }
         }
 

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp 2013-05-28 16:06:51 EDT (Tue, 28 May 2013)
@@ -25,7 +25,6 @@
 int main()
 {
   boost::mutex m;
- m.lock();
   boost::unique_lock<boost::mutex> lk(m, boost::defer_lock);
   BOOST_TEST(lk.mutex() == &m);
   BOOST_TEST(lk.owns_lock() == false);

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/unique_lock/cons/make_unique_lock_defer_lock_pass.cpp 2013-05-28 16:06:51 EDT (Tue, 28 May 2013)
@@ -19,7 +19,6 @@
 int main()
 {
   boost::mutex m;
- m.lock();
 #if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
   auto
 #else


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk