Changed: call throw_exception() function instead of ordinary throw
authorkhizmax <libcds.dev@gmail.com>
Thu, 16 Feb 2017 21:50:14 +0000 (00:50 +0300)
committerkhizmax <libcds.dev@gmail.com>
Thu, 16 Feb 2017 21:50:14 +0000 (00:50 +0300)
cds/details/throw_exception.h
cds/memory/vyukov_queue_pool.h
cds/os/alloc_aligned.h
cds/threading/details/pthread_manager.h
cds/threading/details/wintls_manager.h
cds/urcu/details/check_deadlock.h
change.log

index cd708df8cdfb6e11e0389a6a606d9aeb48cd4381..187c4ffb0255522147a26e4afc4a81039ff97259 100644 (file)
@@ -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.
index 5f4bcf3ef2a6afa038df48846b1fdbbeecbbcb70..8f9ce5d5cfa3d9348bec04e34776d98274270a06 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <cds/details/allocator.h>
 #include <cds/intrusive/vyukov_mpmc_cycle_queue.h>
+#include <cds/details/throw_exception.h>
 
 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:
index 1b5ef3ea20be1b8359b35a79d57e41b733350fab..1dd06d76f842587bb0562c632f1a8ff2dfd7e2fb 100644 (file)
@@ -54,6 +54,7 @@
 #include <memory>
 #include <cds/details/is_aligned.h>
 #include <cds/algo/int_algo.h>
+#include <cds/details/throw_exception.h>
 
 namespace cds {
     /// OS specific wrappers
@@ -177,7 +178,7 @@ namespace cds {
                 assert( cds::beans::is_power2( nAlign ));
                 pointer p = reinterpret_cast<T *>( 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;
             }
index 60b189887c6d5dfb5130078b41ad1e26f95ce74e..a00dda898644cb68833fd615bade746bf138046b 100644 (file)
@@ -35,6 +35,7 @@
 #include <stdio.h>
 #include <pthread.h>
 #include <cds/threading/details/_common.h>
+#include <cds/details/throw_exception.h>
 
 //@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
index ca24c273be03e799c1f844608f59724db8c2bc2b..d41d1b860061f46f0be641b727f06fefdaa088f2 100644 (file)
@@ -34,6 +34,7 @@
 #include <system_error>
 #include <stdio.h>
 #include <cds/threading/details/_common.h>
+#include <cds/details/throw_exception.h>
 
 //@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<ThreadData *>( 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
index 35d70029f476de6d158e23256a254ec70018dab4..56a87c12a07f8e1b8571eca6194ac102ec542208 100644 (file)
@@ -32,6 +32,7 @@
 #define CDSLIB_URCU_DETAILS_CHECK_DEADLOCK_H
 
 #include <cds/urcu/options.h>
+#include <cds/details/throw_exception.h>
 
 //@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());
         }
     };
 
index 12d91f71c34f5cd39f33b61fa07496651d7f0654..d4192ad1e1161138184f82a4fd01dd83e1c26856 100644 (file)
       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),