From: khizmax Date: Thu, 16 Feb 2017 21:50:14 +0000 (+0300) Subject: Changed: call throw_exception() function instead of ordinary throw X-Git-Tag: v2.3.0~172 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=144a4911a25c4f87fe693eb2accdd4fef36de748;p=libcds.git Changed: call throw_exception() function instead of ordinary throw --- diff --git a/cds/details/throw_exception.h b/cds/details/throw_exception.h index cd708df8..187c4ffb 100644 --- a/cds/details/throw_exception.h +++ b/cds/details/throw_exception.h @@ -48,9 +48,9 @@ namespace cds { If exception is disabled, \p %throw_exception() prints an exception message to standard output and call \p abort(). - You may supply your own \p %cds::throw_exception() function; + You can supply your own \p %cds::throw_exception() function; for that you should specify \p -DCDS_USER_DEFINED_THROW_EXCEPTION - in compiler command line. + in compiler command line. @note \p %throw_exception() never returns. If the user-defined \p %throw_exception() returns, the behavior is undefined. diff --git a/cds/memory/vyukov_queue_pool.h b/cds/memory/vyukov_queue_pool.h index 5f4bcf3e..8f9ce5d5 100644 --- a/cds/memory/vyukov_queue_pool.h +++ b/cds/memory/vyukov_queue_pool.h @@ -33,6 +33,7 @@ #include #include +#include namespace cds { namespace memory { @@ -510,7 +511,7 @@ namespace cds { namespace memory { } // The pool is empty - throw std::bad_alloc(); + CDS_THROW_EXCEPTION( std::bad_alloc() ); } ok: diff --git a/cds/os/alloc_aligned.h b/cds/os/alloc_aligned.h index 1b5ef3ea..1dd06d76 100644 --- a/cds/os/alloc_aligned.h +++ b/cds/os/alloc_aligned.h @@ -54,6 +54,7 @@ #include #include #include +#include namespace cds { /// OS specific wrappers @@ -177,7 +178,7 @@ namespace cds { assert( cds::beans::is_power2( nAlign )); pointer p = reinterpret_cast( cds::OS::aligned_malloc( sizeof(T) * nCount, nAlign )); if ( !p ) - throw std::bad_alloc(); + CDS_THROW_EXCEPTION( std::bad_alloc() ); assert( cds::details::is_aligned( p, nAlign )); return p; } diff --git a/cds/threading/details/pthread_manager.h b/cds/threading/details/pthread_manager.h index 60b18988..a00dda89 100644 --- a/cds/threading/details/pthread_manager.h +++ b/cds/threading/details/pthread_manager.h @@ -35,6 +35,7 @@ #include #include #include +#include //@cond namespace cds { namespace threading { @@ -77,15 +78,15 @@ namespace cds { namespace threading { static void init() { pthread_error_code nErr; - if ( (nErr = pthread_key_create( &m_key, key_destructor )) != 0 ) - throw pthread_exception( nErr, "pthread_key_create" ); + if ( ( nErr = pthread_key_create( &m_key, key_destructor ) ) != 0 ) + CDS_THROW_EXCEPTION( pthread_exception( nErr, "pthread_key_create" )); } static void fini() { pthread_error_code nErr; - if ( (nErr = pthread_key_delete( m_key )) != 0 ) - throw pthread_exception( nErr, "pthread_key_delete" ); + if ( ( nErr = pthread_key_delete( m_key ) ) != 0 ) + CDS_THROW_EXCEPTION( pthread_exception( nErr, "pthread_key_delete" )); } static ThreadData * get() @@ -97,8 +98,8 @@ namespace cds { namespace threading { { pthread_error_code nErr; ThreadData * pData = new ThreadData; - if ( ( nErr = pthread_setspecific( m_key, pData )) != 0 ) - throw pthread_exception( nErr, "pthread_setspecific" ); + if ( ( nErr = pthread_setspecific( m_key, pData ) ) != 0 ) + CDS_THROW_EXCEPTION( pthread_exception( nErr, "pthread_setspecific" )); } static void free() { @@ -188,7 +189,7 @@ namespace cds { namespace threading { pData->init(); } else - throw pthread_exception( -1, "cds::threading::pthread::Manager::attachThread" ); + CDS_THROW_EXCEPTION( pthread_exception( -1, "cds::threading::pthread::Manager::attachThread" )); } /// This method must be called in end of thread execution @@ -204,11 +205,11 @@ namespace cds { namespace threading { assert( pData ); if ( pData ) { - if ( pData->fini()) + if ( pData->fini() ) _threadData( do_detachThread ); } else - throw pthread_exception( -1, "cds::threading::pthread::Manager::detachThread" ); + CDS_THROW_EXCEPTION( pthread_exception( -1, "cds::threading::pthread::Manager::detachThread" )); } /// Returns ThreadData pointer for the current thread diff --git a/cds/threading/details/wintls_manager.h b/cds/threading/details/wintls_manager.h index ca24c273..d41d1b86 100644 --- a/cds/threading/details/wintls_manager.h +++ b/cds/threading/details/wintls_manager.h @@ -34,6 +34,7 @@ #include #include #include +#include //@cond namespace cds { namespace threading { @@ -77,8 +78,8 @@ namespace cds { namespace threading { static void init() { if ( m_key == TLS_OUT_OF_INDEXES ) { - if ( (m_key = ::TlsAlloc()) == TLS_OUT_OF_INDEXES ) - throw api_exception( ::GetLastError(), "TlsAlloc" ); + if ( ( m_key = ::TlsAlloc() ) == TLS_OUT_OF_INDEXES ) + CDS_THROW_EXCEPTION( api_exception( ::GetLastError(), "TlsAlloc" )); } } @@ -86,7 +87,7 @@ namespace cds { namespace threading { { if ( m_key != TLS_OUT_OF_INDEXES ) { if ( ::TlsFree( m_key ) == 0 ) - throw api_exception( ::GetLastError(), "TlsFree" ); + CDS_THROW_EXCEPTION( api_exception( ::GetLastError(), "TlsFree" )); m_key = TLS_OUT_OF_INDEXES; } } @@ -95,8 +96,8 @@ namespace cds { namespace threading { { api_error_code nErr; void * pData = ::TlsGetValue( m_key ); - if ( pData == nullptr && (nErr = ::GetLastError()) != ERROR_SUCCESS ) - throw api_exception( nErr, "TlsGetValue" ); + if ( pData == nullptr && ( nErr = ::GetLastError() ) != ERROR_SUCCESS ) + CDS_THROW_EXCEPTION( api_exception( nErr, "TlsGetValue" )); return reinterpret_cast( pData ); } @@ -104,7 +105,7 @@ namespace cds { namespace threading { { ThreadData * pData = new ThreadData; if ( !::TlsSetValue( m_key, pData )) - throw api_exception( ::GetLastError(), "TlsSetValue" ); + CDS_THROW_EXCEPTION( api_exception( ::GetLastError(), "TlsSetValue" )); } static void free() { @@ -186,7 +187,7 @@ namespace cds { namespace threading { if ( pData ) pData->init(); else - throw api_exception( api_error_code(-1), "cds::threading::wintls::Manager::attachThread" ); + CDS_THROW_EXCEPTION( api_exception( api_error_code(-1), "cds::threading::wintls::Manager::attachThread" )); } /// This method must be called in end of thread execution @@ -206,7 +207,7 @@ namespace cds { namespace threading { _threadData( do_detachThread ); } else - throw api_exception( api_error_code(-1), "cds::threading::winapi::Manager::detachThread" ); + CDS_THROW_EXCEPTION( api_exception( api_error_code(-1), "cds::threading::winapi::Manager::detachThread" )); } /// Returns ThreadData pointer for the current thread diff --git a/cds/urcu/details/check_deadlock.h b/cds/urcu/details/check_deadlock.h index 35d70029..56a87c12 100644 --- a/cds/urcu/details/check_deadlock.h +++ b/cds/urcu/details/check_deadlock.h @@ -32,6 +32,7 @@ #define CDSLIB_URCU_DETAILS_CHECK_DEADLOCK_H #include +#include //@cond namespace cds { namespace urcu { namespace details { @@ -43,7 +44,7 @@ namespace cds { namespace urcu { namespace details { { assert( !RCU::is_locked()); if ( RCU::is_locked()) - throw cds::urcu::rcu_deadlock(); + CDS_THROW_EXCEPTION( cds::urcu::rcu_deadlock()); } }; diff --git a/change.log b/change.log index 12d91f71..d4192ad1 100644 --- a/change.log +++ b/change.log @@ -13,6 +13,11 @@ External API of gc::DHP class is changed: now only initial count of hazard pointers can be specified in the constructor. Like new gc::HP, the new gc::DHP supports an external allocator. + - Changed: exception handling. Now, exceptions raise by invoking new + cds::throw_exception() function. If you compile your code with exception disabled, + the function prints an exception message to stdout and calls abort() + instead of throwing. You can provide your own cds::throw_exception() function + and compile libcds with -DCDS_USER_DEFINED_THROW_EXCEPTION. - Fixed a bug in BronsonAVLTreeMap::extract_min()/extract_max()/clear(). - Added more flat-combining queue tests, thanks to Marsel Galimullin. - Changed cmake scripts to support MacOS and ARMv7/ARMv8 (64 bit),