Removed cds::Exception class, all exception from the library is based on different...
[libcds.git] / cds / threading / details / pthread_manager.h
index 3ed88ccdabbb75b7687cfb2620304409c685abee..fe4e0171b7f9a97d61d756e4e658af20520f14cd 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef __CDS_THREADING_DETAILS_PTHREAD_MANAGER_H
 #define __CDS_THREADING_DETAILS_PTHREAD_MANAGER_H
 
+#include <system_error>
 #include <stdio.h>
 #include <pthread.h>
 #include <cds/threading/details/_common.h>
@@ -23,18 +24,13 @@ namespace cds { namespace threading {
             typedef int pthread_error_code;
 
             /// pthread exception
-            class pthread_exception: public cds::Exception {
-            public:
-                const pthread_error_code    m_errCode   ;   ///< pthread error code, -1 if no pthread error code
+            class pthread_exception: public std::system_error
+            {
             public:
                 /// Exception constructor
-                pthread_exception( pthread_error_code nCode, const char * pszFunction )
-                    : m_errCode( nCode )
-                {
-                    char buf[256];
-                    sprintf( buf, "Pthread error %i [function %s]", nCode, pszFunction );
-                    m_strMsg = buf;
-                }
+                pthread_exception( int nCode, const char * pszFunction )
+                    : std::system_error( nCode, std::system_category(), pszFunction )
+                {}
             };
 
             /// pthread TLS key holder
@@ -79,7 +75,7 @@ namespace cds { namespace threading {
                 static void free()
                 {
                     ThreadData * p = get();
-                    pthread_setspecific( m_key, NULL );
+                    pthread_setspecific( m_key, nullptr );
                     if ( p )
                         delete p;
                 }
@@ -106,12 +102,12 @@ namespace cds { namespace threading {
                     case do_checkData:
                         return Holder::get();
                     case do_attachThread:
-                        if ( Holder::get() == NULL )
+                        if ( Holder::get() == nullptr )
                             Holder::alloc();
                         return Holder::get();
                     case do_detachThread:
                         Holder::free();
-                        return NULL;
+                        return nullptr;
                     case init_holder:
                     case fini_holder:
                         break;
@@ -119,7 +115,7 @@ namespace cds { namespace threading {
                         assert( false ) ;   // anything forgotten?..
                 }
                 assert(false)   ;   // how did we get here?
-                return NULL;
+                return nullptr;
             }
             //@endcond
 
@@ -145,12 +141,12 @@ namespace cds { namespace threading {
             /// Checks whether current thread is attached to \p libcds feature or not.
             static bool isThreadAttached()
             {
-                return _threadData( do_checkData ) != NULL;
+                return _threadData( do_checkData ) != nullptr;
             }
 
             /// This method must be called in beginning of thread execution
             /**
-                If TLS pointer to manager's data is NULL, pthread_exception is thrown
+                If TLS pointer to manager's data is \p nullptr, pthread_exception is thrown
                 with code = -1.
                 If an error occurs in call of pthread API function, pthread_exception is thrown
                 with pthread error code.
@@ -158,7 +154,7 @@ namespace cds { namespace threading {
             static void attachThread()
             {
                 ThreadData * pData = _threadData( do_attachThread );
-                assert( pData != NULL );
+                assert( pData );
 
                 if ( pData ) {
                     pData->init();
@@ -169,7 +165,7 @@ namespace cds { namespace threading {
 
             /// This method must be called in end of thread execution
             /**
-                If TLS pointer to manager's data is NULL, pthread_exception is thrown
+                If TLS pointer to manager's data is \p nullptr, pthread_exception is thrown
                 with code = -1.
                 If an error occurs in call of pthread API function, pthread_exception is thrown
                 with pthread error code.
@@ -177,7 +173,7 @@ namespace cds { namespace threading {
             static void detachThread()
             {
                 ThreadData * pData = _threadData( do_getData );
-                assert( pData != NULL );
+                assert( pData );
 
                 if ( pData ) {
                     if ( pData->fini() )
@@ -204,26 +200,15 @@ namespace cds { namespace threading {
                 return *(_threadData( do_getData )->m_hpManager);
             }
 
-            /// Get gc::HRC thread GC implementation for current thread
-            /**
-                The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
-                or if you did not use gc::HRC.
-                To initialize gc::HRC GC you must constuct cds::gc::HRC object in the beginning of your application
-            */
-            static gc::HRC::thread_gc_impl&   getHRCGC()
-            {
-                return *(_threadData( do_getData )->m_hrcManager);
-            }
-
-            /// Get gc::PTB thread GC implementation for current thread
+            /// Get gc::DHP thread GC implementation for current thread
             /**
                 The object returned may be uninitialized if you did not call attachThread in the beginning of thread execution
-                or if you did not use gc::PTB.
-                To initialize gc::PTB GC you must constuct cds::gc::PTB object in the beginning of your application
+                or if you did not use gc::DHP.
+                To initialize gc::DHP GC you must constuct cds::gc::DHP object in the beginning of your application
             */
-            static gc::PTB::thread_gc_impl&   getPTBGC()
+            static gc::DHP::thread_gc_impl&   getDHPGC()
             {
-                return *(_threadData( do_getData )->m_ptbManager);
+                return *(_threadData( do_getData )->m_dhpManager);
             }
 
             //@cond