#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>
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
static void free()
{
ThreadData * p = get();
- pthread_setspecific( m_key, NULL );
+ pthread_setspecific( m_key, nullptr );
if ( p )
delete p;
}
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;
assert( false ) ; // anything forgotten?..
}
assert(false) ; // how did we get here?
- return NULL;
+ return nullptr;
}
//@endcond
/// 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.
static void attachThread()
{
ThreadData * pData = _threadData( do_attachThread );
- assert( pData != NULL );
+ assert( pData );
if ( pData ) {
pData->init();
/// 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.
static void detachThread()
{
ThreadData * pData = _threadData( do_getData );
- assert( pData != NULL );
+ assert( pData );
if ( pData ) {
if ( pData->fini() )
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