Check return values of pthread_* calls with BOOST_VERIFY, per #8898

This commit is contained in:
Peter Dimov
2013-12-12 02:36:33 +02:00
parent 4c8a558982
commit bba3b446bd

View File

@@ -19,6 +19,7 @@
// //
#include <boost/detail/sp_typeinfo.hpp> #include <boost/detail/sp_typeinfo.hpp>
#include <boost/assert.hpp>
#include <pthread.h> #include <pthread.h>
namespace boost namespace boost
@@ -46,15 +47,15 @@ public:
// HPUX 10.20 / DCE has a nonstandard pthread_mutex_init // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
#if defined(__hpux) && defined(_DECTHREADS_) #if defined(__hpux) && defined(_DECTHREADS_)
pthread_mutex_init( &m_, pthread_mutexattr_default ); BOOST_VERIFY( pthread_mutex_init( &m_, pthread_mutexattr_default ) == 0 );
#else #else
pthread_mutex_init( &m_, 0 ); BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
#endif #endif
} }
virtual ~sp_counted_base() // nothrow virtual ~sp_counted_base() // nothrow
{ {
pthread_mutex_destroy( &m_ ); BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
} }
// dispose() is called when use_count_ drops to zero, to release // dispose() is called when use_count_ drops to zero, to release
@@ -74,24 +75,24 @@ public:
void add_ref_copy() void add_ref_copy()
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
++use_count_; ++use_count_;
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
} }
bool add_ref_lock() // true on success bool add_ref_lock() // true on success
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
bool r = use_count_ == 0? false: ( ++use_count_, true ); bool r = use_count_ == 0? false: ( ++use_count_, true );
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
return r; return r;
} }
void release() // nothrow void release() // nothrow
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
long new_use_count = --use_count_; long new_use_count = --use_count_;
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
if( new_use_count == 0 ) if( new_use_count == 0 )
{ {
@@ -102,16 +103,16 @@ public:
void weak_add_ref() // nothrow void weak_add_ref() // nothrow
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
++weak_count_; ++weak_count_;
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
} }
void weak_release() // nothrow void weak_release() // nothrow
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
long new_weak_count = --weak_count_; long new_weak_count = --weak_count_;
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
if( new_weak_count == 0 ) if( new_weak_count == 0 )
{ {
@@ -121,9 +122,9 @@ public:
long use_count() const // nothrow long use_count() const // nothrow
{ {
pthread_mutex_lock( &m_ ); BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
long r = use_count_; long r = use_count_;
pthread_mutex_unlock( &m_ ); BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
return r; return r;
} }