[complement-svn] SF.net SVN: complement:[1953] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-07-30 17:27:09
|
Revision: 1953 http://complement.svn.sourceforge.net/complement/?rev=1953&view=rev Author: complement Date: 2008-07-30 17:27:06 +0000 (Wed, 30 Jul 2008) Log Message: ----------- throw system_error when problem detected in mutexes and conditions fix barrier::wait: pthread_barrier_wait return PTHREAD_BARRIER_SERIAL_THREAD for one thread and 0 for others; fix error processing in semaphore: sem_* functions report error via errno, not via return value. Modified Paths: -------------- trunk/complement/explore/include/mt/condition_variable trunk/complement/explore/include/mt/mutex trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc Modified: trunk/complement/explore/include/mt/condition_variable =================================================================== --- trunk/complement/explore/include/mt/condition_variable 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/include/mt/condition_variable 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:18:13 ptr> +// -*- C++ -*- Time-stamp: <08/07/30 20:49:38 ptr> /* * Copyright (c) 1997-1999, 2002-2008 @@ -27,8 +27,8 @@ #ifdef __FIT_PTHREADS # include <semaphore.h> #endif +#include <mt/system_error> - namespace std { namespace tr2 { @@ -104,7 +104,7 @@ int ret = pthread_cond_wait( &_cond, const_cast<pthread_mutex_t *>(&lock.m->_M_lock) ); if ( ret ) { lock.lock(); - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -128,7 +128,7 @@ if ( ret == ETIMEDOUT ) { return false; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif return true; @@ -259,7 +259,7 @@ int ret = pthread_cond_wait( &_cond, lock.native_handle() ); if ( ret ) { lock.lock(); - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -284,7 +284,7 @@ if ( ret == ETIMEDOUT ) { return false; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } #endif #ifdef __FIT_WIN32THREADS @@ -424,8 +424,9 @@ SetEvent( _cond ); #endif #ifdef __FIT_PTHREADS - if ( pthread_cond_signal( &_cond ) ) { - // throw system_error + int ret = pthread_cond_signal( &_cond ); + if ( ret ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -448,8 +449,9 @@ } #endif #ifdef __FIT_PTHREADS - if ( pthread_cond_broadcast( &_cond ) ) { - // throw system_error + int ret = pthread_cond_broadcast( &_cond ); + if ( ret ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } @@ -478,7 +480,7 @@ while ( !_val ) { ret = pthread_cond_wait( &_cond, &_lock._M_lock ); if ( ret ) { - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } } #endif @@ -498,7 +500,7 @@ if ( ret == ETIMEDOUT ) { return _val; } - // throw system_error + throw std::system_error( ret, std::get_posix_category() ); } } #endif @@ -601,9 +603,8 @@ } #endif #ifdef __FIT_PTHREADS - int ret = sem_wait( &_sem ); - if ( ret != 0 ) { - // throw system_error + if ( sem_wait( &_sem ) ) { + throw std::system_error( errno, std::get_posix_category() ); } #endif } @@ -614,12 +615,11 @@ return _cnt > 0 ? (--_cnt, this->wait()) : -1; #endif #ifdef __FIT_PTHREADS - int ret = sem_trywait( &_sem ); - if ( ret != 0 ) { - if ( ret == EBUSY ) { + if ( sem_trywait( &_sem ) ) { + if ( errno == std::posix_error::resource_unavailable_try_again ) { return false; } - // throw system_error + throw std::system_error( errno, std::get_posix_category() ); } return true; #endif @@ -632,12 +632,11 @@ t.tv_sec = abs_time.seconds_since_epoch(); t.tv_nsec = static_cast<long>( abs_time.nanoseconds_since_epoch().count() % nanoseconds::ticks_per_second ); # if !(defined(__FreeBSD__) || defined(__OpenBSD__)) - int ret = sem_timedwait( &_sem, &t ); - if ( ret != 0 ) { - if ( ret == ETIMEDOUT ) { + if ( sem_timedwait( &_sem, &t ) ) { + if ( errno == std::posix_error::timed_out ) { return false; } - // throw system_error + throw std::system_error( errno, std::get_posix_category() ); } # endif #endif @@ -690,9 +689,8 @@ } #endif #ifdef __FIT_PTHREADS - int ret = sem_post( &_sem ); - if ( ret != 0 ) { - // throw system_error + if ( sem_post( &_sem ) ) { + throw std::system_error( errno, std::get_posix_category() ); } #endif } @@ -704,9 +702,8 @@ #endif #ifdef __FIT_PTHREADS int v; - int e = sem_getvalue( &_sem, &v ); - if ( e != 0 ) { - // throw system_error + if ( sem_getvalue( &_sem, &v ) ) { + throw std::system_error( errno, std::get_posix_category() ); } return v; @@ -755,8 +752,8 @@ { #ifdef __FIT_PTHREADS int ret = pthread_barrier_wait( &_barr ); - if ( ret != 0 ) { - // throw system_error + if ( ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0 ) { + throw std::system_error( ret, std::get_posix_category() ); } #endif } Modified: trunk/complement/explore/include/mt/mutex =================================================================== --- trunk/complement/explore/include/mt/mutex 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/include/mt/mutex 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:20:36 ptr> +// -*- C++ -*- Time-stamp: <08/07/30 19:44:33 ptr> /* * Copyright (c) 1997-1999, 2002-2008 @@ -98,15 +98,17 @@ pthread_mutexattr_init( &att ); # ifdef __FIT_PSHARED_MUTEX if ( SCOPE ) { - if ( pthread_mutexattr_setpshared( &att, PTHREAD_PROCESS_SHARED ) != 0 ) { - throw std::invalid_argument( detail::_notpshared ); + int ret = pthread_mutexattr_setpshared( &att, PTHREAD_PROCESS_SHARED ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), detail::_notpshared ); } } # endif // __FIT_PSHARED_MUTEX # ifdef __FIT_XSI_THR // Unix 98 or X/Open System Interfaces Extention if ( RECURSIVE_SAFE ) { - if ( pthread_mutexattr_settype( &att, PTHREAD_MUTEX_RECURSIVE ) != 0 ) { - throw std::invalid_argument( detail::_notrecursive ); + int ret = pthread_mutexattr_settype( &att, PTHREAD_MUTEX_RECURSIVE ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), detail::_notrecursive ); } } # endif @@ -218,9 +220,9 @@ void lock() { #ifdef __FIT_PTHREADS - int /* std::error_catalog::value_type */ e = pthread_mutex_lock( &this->_M_lock ); + int e = pthread_mutex_lock( &this->_M_lock ); if ( e ) { - // throw std::system_error( e, native_catalog ); + throw std::system_error( e, std::get_posix_category() ); } #endif #ifdef __FIT_WIN32THREADS @@ -514,8 +516,9 @@ pthread_rwlockattr_t att; pthread_rwlockattr_init( &att ); # ifdef __FIT_PSHARED_MUTEX - if ( pthread_rwlockattr_setpshared( &att, PTHREAD_PROCESS_SHARED ) != 0 ) { - throw std::invalid_argument( std::tr2::detail::_notpshared ); + int ret = pthread_rwlockattr_setpshared( &att, PTHREAD_PROCESS_SHARED ); + if ( ret != 0 ) { + throw std::system_error( ret, std::get_posix_category(), std::tr2::detail::_notpshared ); } # endif // __FIT_PSHARED_MUTEX pthread_rwlock_init( &_M_lock, &att ); Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,5 +1,12 @@ 2008-07-30 Petr Ovtchenkov <pt...@is...> + * condition_variable: throw system_error when problem detected; + fix barrier::wait---PTHREAD_BARRIER_SERIAL_THREAD is also + normal return value; fix error processing in semaphore---sem_* + functions indicate error via errno, not via return; + + * mutex: throw system_error when problem detected; + * uid.cc: use system_error for detailed report about problem; * libxmt: bump revision to 2.0.9. Modified: trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc =================================================================== --- trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-30 17:26:23 UTC (rev 1952) +++ trunk/complement/explore/lib/mt/ut/mt_test_wg21.cc 2008-07-30 17:27:06 UTC (rev 1953) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/07 14:23:07 yeti> +// -*- C++ -*- Time-stamp: <08/07/30 20:51:24 ptr> /* * Copyright (c) 2006-2008 @@ -137,13 +137,18 @@ void thread_func3() { - EXAM_CHECK_ASYNC( val == 0 ); + try { + EXAM_CHECK_ASYNC( val == 0 ); - bar.wait(); + bar.wait(); - std::tr2::lock_guard<std::tr2::mutex> lock( lk ); + std::tr2::lock_guard<std::tr2::mutex> lock( lk ); - ++val; + ++val; + } + catch ( std::runtime_error& err ) { + EXAM_ERROR_ASYNC( err.what() ); + } } int EXAM_IMPL(mt_test_wg21::barrier) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |