From: khizmax Date: Fri, 19 Sep 2014 21:05:08 +0000 (+0400) Subject: Revert "Replace cds::OS::ThreadId with std::thread::id, cds::OS::nullThreadId() with... X-Git-Tag: v2.0.0~328 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=16e2cded8b30a53c11736eb71837c112dc6e3c3f Revert "Replace cds::OS::ThreadId with std::thread::id, cds::OS::nullThreadId() with std::thread::id()" This reverts commit 696ef88ac5b9503da2300246865ba1671d87aae3. --- diff --git a/cds/gc/hrc/hrc.h b/cds/gc/hrc/hrc.h index 743248e5..ff523931 100644 --- a/cds/gc/hrc/hrc.h +++ b/cds/gc/hrc/hrc.h @@ -294,7 +294,7 @@ namespace cds { namespace gc { { thread_list_node * m_pNext ; ///< next list record ThreadGC * m_pOwner ; ///< Owner of record - CDS_ATOMIC::atomic m_idOwner ; ///< Id of thread owned; 0 - record is free + CDS_ATOMIC::atomic m_idOwner ; ///< Id of thread owned; 0 - record is free bool m_bFree ; ///< Node is help-scanned //@cond @@ -302,14 +302,14 @@ namespace cds { namespace gc { : thread_descriptor( HzpMgr ), m_pNext( nullptr ), m_pOwner( nullptr ), - m_idOwner( std::thread::id() ), + m_idOwner(cds::OS::c_NullThreadId), m_bFree( false ) {} ~thread_list_node() { assert( m_pOwner == nullptr ); - assert( m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == std::thread::id() ); + assert( m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == cds::OS::c_NullThreadId ); } //@endcond }; diff --git a/cds/gc/hzp/hzp.h b/cds/gc/hzp/hzp.h index 568c4835..fc3dd20c 100644 --- a/cds/gc/hzp/hzp.h +++ b/cds/gc/hzp/hzp.h @@ -208,20 +208,20 @@ namespace cds { struct hplist_node: public details::HPRec { hplist_node * m_pNextNode ; ///< next hazard ptr record in list - CDS_ATOMIC::atomic m_idOwner; ///< Owner thread id; 0 - the record is free (not owned) + CDS_ATOMIC::atomic m_idOwner ; ///< Owner thread id; 0 - the record is free (not owned) CDS_ATOMIC::atomic m_bFree ; ///< true if record if free (not owned) //@cond hplist_node( const GarbageCollector& HzpMgr ) : HPRec( HzpMgr ), m_pNextNode(NULL), - m_idOwner( std::thread::id() ), + m_idOwner( OS::c_NullThreadId ), m_bFree( true ) {} ~hplist_node() { - assert( m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == std::thread::id() ); + assert( m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == OS::c_NullThreadId ); assert( m_bFree.load(CDS_ATOMIC::memory_order_relaxed) ); } //@endcond diff --git a/cds/intrusive/cuckoo_set.h b/cds/intrusive/cuckoo_set.h index 42db2d66..dd07159d 100644 --- a/cds/intrusive/cuckoo_set.h +++ b/cds/intrusive/cuckoo_set.h @@ -648,7 +648,7 @@ namespace cds { namespace intrusive { typedef cds::details::Allocator< lock_array_type, allocator_type > lock_array_allocator; typedef unsigned long long owner_t; - typedef std::thread::id threadId_t; + typedef cds::OS::ThreadId threadId_t; typedef cds::lock::Spin spinlock_type; typedef cds::lock::scoped_lock< spinlock_type > scoped_spinlock; @@ -681,7 +681,7 @@ namespace cds { namespace intrusive { void acquire( size_t const * arrHash, lock_array_ptr * pLockArr, lock_type ** parrLock ) { - owner_t me = (owner_t)std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); owner_t who; back_off bkoff; @@ -760,7 +760,7 @@ namespace cds { namespace intrusive { void acquire_all() { - owner_t me = (owner_t)std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); back_off bkoff; while ( true ) { @@ -784,7 +784,7 @@ namespace cds { namespace intrusive { void acquire_resize( lock_array_ptr * pOldLocks ) { - owner_t me = (owner_t)std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); while ( true ) { { diff --git a/cds/intrusive/mspriority_queue.h b/cds/intrusive/mspriority_queue.h index b502fd2d..ce277758 100644 --- a/cds/intrusive/mspriority_queue.h +++ b/cds/intrusive/mspriority_queue.h @@ -169,7 +169,7 @@ namespace cds { namespace intrusive { protected: //@cond - typedef std::thread::id tag_type; + typedef cds::OS::ThreadId tag_type; enum tag_value { Available = -1, @@ -255,7 +255,7 @@ namespace cds { namespace intrusive { */ bool push( value_type& val ) { - tag_type const curId = std::this_thread::get_id(); + tag_type const curId = cds::OS::getCurrentThreadId(); // Insert new item at bottom of the heap m_Lock.lock(); diff --git a/cds/intrusive/striped_set/striping_policy.h b/cds/intrusive/striped_set/striping_policy.h index 9a593c9a..1e3ec4c3 100644 --- a/cds/intrusive/striped_set/striping_policy.h +++ b/cds/intrusive/striped_set/striping_policy.h @@ -142,7 +142,7 @@ namespace cds { namespace intrusive { namespace striped_set { typedef cds::details::Allocator< lock_array_type, allocator_type > lock_array_allocator; typedef unsigned long long owner_t; - typedef std::thread::id threadId_t; + typedef cds::OS::ThreadId threadId_t; typedef cds::lock::Spin spinlock_type; typedef cds::lock::scoped_lock< spinlock_type > scoped_spinlock; @@ -175,7 +175,7 @@ namespace cds { namespace intrusive { namespace striped_set { lock_type& acquire( size_t nHash ) { - owner_t me = (owner_t) std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); owner_t who; back_off bkoff; @@ -206,7 +206,7 @@ namespace cds { namespace intrusive { namespace striped_set { lock_array_ptr acquire_all() { - owner_t me = (owner_t)std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); owner_t who; back_off bkoff; @@ -242,7 +242,7 @@ namespace cds { namespace intrusive { namespace striped_set { bool acquire_resize() { - owner_t me = (owner_t)std::this_thread::get_id(); + owner_t me = (owner_t) cds::OS::getCurrentThreadId(); back_off bkoff; for (unsigned int nAttempts = 0; nAttempts < 32; ++nAttempts ) { diff --git a/cds/lock/spinlock.h b/cds/lock/spinlock.h index 76625d0c..daf9e9e8 100644 --- a/cds/lock/spinlock.h +++ b/cds/lock/spinlock.h @@ -50,18 +50,18 @@ namespace cds { class Spinlock { public: - typedef Backoff backoff_strategy; ///< back-off strategy type + typedef Backoff backoff_strategy ; ///< back-off strategy type private: - CDS_ATOMIC::atomic m_spin; ///< Spin + CDS_ATOMIC::atomic m_spin ; ///< Spin # ifdef CDS_DEBUG - typename std::thread::id m_dbgOwnerId; ///< Owner thread id (only for debug mode) + typename OS::ThreadId m_dbgOwnerId ; ///< Owner thread id (only for debug mode) # endif public: /// Construct free (unlocked) spin-lock Spinlock() CDS_NOEXCEPT # ifdef CDS_DEBUG - :m_dbgOwnerId( std::thread::id() ) + :m_dbgOwnerId( OS::c_NullThreadId ) # endif { m_spin.store( false, CDS_ATOMIC::memory_order_relaxed ); @@ -73,7 +73,7 @@ namespace cds { */ Spinlock( bool bLocked ) CDS_NOEXCEPT # ifdef CDS_DEBUG - :m_dbgOwnerId( bLocked ? std::this_thread::get_id() : std::thread::id() ) + :m_dbgOwnerId( bLocked ? OS::getCurrentThreadId() : OS::c_NullThreadId ) # endif { m_spin.store( bLocked, CDS_ATOMIC::memory_order_relaxed ); @@ -88,7 +88,7 @@ namespace cds { Spinlock(const Spinlock& ) CDS_NOEXCEPT : m_spin( false ) # ifdef CDS_DEBUG - , m_dbgOwnerId( std::thread::id() ) + , m_dbgOwnerId( OS::c_NullThreadId ) # endif {} @@ -124,7 +124,7 @@ namespace cds { CDS_DEBUG_DO( if ( !bCurrent ) { - m_dbgOwnerId = std::this_thread::get_id(); + m_dbgOwnerId = OS::getCurrentThreadId(); } ) return !bCurrent; @@ -158,7 +158,7 @@ namespace cds { Backoff backoff; // Deadlock detected - assert( m_dbgOwnerId != std::this_thread::get_id() ); + assert( m_dbgOwnerId != OS::getCurrentThreadId() ); // TATAS algorithm while ( !tryLock() ) { @@ -166,7 +166,7 @@ namespace cds { backoff(); } } - assert( m_dbgOwnerId == std::this_thread::get_id() ); + assert( m_dbgOwnerId == OS::getCurrentThreadId() ); } /// Unlock the spin-lock. Debug version: deadlock may be detected @@ -174,8 +174,8 @@ namespace cds { { assert( m_spin.load( CDS_ATOMIC::memory_order_relaxed ) ); - assert( m_dbgOwnerId == std::this_thread::get_id() ); - CDS_DEBUG_DO( m_dbgOwnerId = std::thread::id() );) + assert( m_dbgOwnerId == OS::getCurrentThreadId() ); + CDS_DEBUG_DO( m_dbgOwnerId = OS::c_NullThreadId; ) m_spin.store( false, CDS_ATOMIC::memory_order_release ); } @@ -195,7 +195,7 @@ namespace cds { template class ReentrantSpinT { - typedef std::thread::id thread_id; ///< The type of thread id + typedef OS::ThreadId thread_id ; ///< The type of thread id public: typedef Integral integral_type ; ///< The integral type @@ -203,7 +203,7 @@ namespace cds { private: CDS_ATOMIC::atomic m_spin ; ///< spin-lock atomic - thread_id m_OwnerId ; ///< Owner thread id. If spin-lock is not locked it usually equals to std::thread::id() + thread_id m_OwnerId ; ///< Owner thread id. If spin-lock is not locked it usually equals to OS::c_NullThreadId private: //@cond @@ -214,7 +214,7 @@ namespace cds { void free() CDS_NOEXCEPT { - m_OwnerId = std::thread::id(); + m_OwnerId = OS::c_NullThreadId; } bool isOwned( thread_id tid ) const CDS_NOEXCEPT @@ -264,7 +264,7 @@ namespace cds { /// Default constructor initializes spin to free (unlocked) state ReentrantSpinT() CDS_NOEXCEPT : m_spin(0) - , m_OwnerId( std::thread::id() ) + , m_OwnerId( OS::c_NullThreadId ) {} /// Dummy copy constructor @@ -275,13 +275,13 @@ namespace cds { */ ReentrantSpinT(const ReentrantSpinT& ) CDS_NOEXCEPT : m_spin(0) - , m_OwnerId( std::thread::id() ) + , m_OwnerId( OS::c_NullThreadId ) {} /// Construct object for specified state ReentrantSpinT(bool bLocked) CDS_NOEXCEPT - : m_spin(0), - m_OwnerId( std::thread::id() ) + : m_spin(0) + , m_OwnerId( OS::c_NullThreadId ) { if ( bLocked ) lock(); @@ -294,13 +294,13 @@ namespace cds { */ bool is_locked() const CDS_NOEXCEPT { - return !(m_spin.load( CDS_ATOMIC::memory_order_relaxed ) == 0 || isOwned( std::this_thread::get_id() )); + return !( m_spin.load( CDS_ATOMIC::memory_order_relaxed ) == 0 || isOwned( cds::OS::getCurrentThreadId() )); } /// Try to lock the spin-lock (synonym for \ref try_lock) bool tryLock() CDS_NOEXCEPT { - thread_id tid = std::this_thread::get_id(); + thread_id tid = OS::getCurrentThreadId(); if ( tryLockOwned( tid ) ) return true; if ( tryAcquireLock()) { @@ -324,7 +324,7 @@ namespace cds { CDS_NOEXCEPT_( noexcept( tryAcquireLock(nTryCount) )) # endif { - thread_id tid = std::this_thread::get_id(); + thread_id tid = OS::getCurrentThreadId(); if ( tryLockOwned( tid ) ) return true; if ( tryAcquireLock( nTryCount )) { @@ -353,7 +353,7 @@ namespace cds { /// Lock the object waits if it is busy void lock() CDS_NOEXCEPT { - thread_id tid = std::this_thread::get_id(); + thread_id tid = OS::getCurrentThreadId(); if ( !tryLockOwned( tid ) ) { acquireLock(); beOwner( tid ); @@ -363,7 +363,7 @@ namespace cds { /// Unlock the spin-lock. Return @p true if the current thread is owner of spin-lock @p false otherwise bool unlock() CDS_NOEXCEPT { - if ( isOwned( std::this_thread::get_id() ) ) { + if ( isOwned( OS::getCurrentThreadId() ) ) { integral_type n = m_spin.load( CDS_ATOMIC::memory_order_relaxed ); if ( n > 1 ) m_spin.store( n - 1, CDS_ATOMIC::memory_order_relaxed ); @@ -377,10 +377,10 @@ namespace cds { } /// Change the owner of locked spin-lock. May be called by thread that is owner of the spin-lock - bool changeOwner( std::thread::id newOwnerId ) CDS_NOEXCEPT + bool changeOwner( OS::ThreadId newOwnerId ) CDS_NOEXCEPT { - if ( isOwned( std::this_thread::get_id() ) ) { - assert( newOwnerId != std::thread::id() ); + if ( isOwned( OS::getCurrentThreadId() ) ) { + assert( newOwnerId != OS::c_NullThreadId ); m_OwnerId = newOwnerId; return true; } diff --git a/cds/os/posix/thread.h b/cds/os/posix/thread.h index da77ea65..76592ca8 100644 --- a/cds/os/posix/thread.h +++ b/cds/os/posix/thread.h @@ -8,8 +8,15 @@ namespace cds { namespace OS { /// posix-related wrappers namespace posix { + + /// Posix thread id type + typedef std::thread::native_thread_handle ThreadId; + + /// Get current thread id + static inline ThreadId getCurrentThreadId() { return pthread_self(); } + /// Checks if thread \p id is alive - static inline bool isThreadAlive( std::thread::id id ) + static inline bool isThreadAlive( ThreadId id ) { // if sig is zero, error checking is performed but no signal is actually sent. // ESRCH - No thread could be found corresponding to that specified by the given thread ID @@ -25,6 +32,10 @@ namespace cds { namespace OS { } // namespace posix + using posix::ThreadId; + constexpr const ThreadId c_NullThreadId = 0; + + using posix::getCurrentThreadId; using posix::isThreadAlive; using posix::backoff; diff --git a/cds/os/win/thread.h b/cds/os/win/thread.h index e7feb557..85877573 100644 --- a/cds/os/win/thread.h +++ b/cds/os/win/thread.h @@ -9,8 +9,17 @@ namespace cds { namespace OS { /// Windows-specific functions namespace Win32 { + /// OS-specific type of thread identifier + typedef DWORD ThreadId; + + /// Get current thread id + static inline ThreadId getCurrentThreadId() + { + return ::GetCurrentThreadId(); + } + /// Tests whether the thread is alive - static inline bool isThreadAlive( std::thread::id id ) + static inline bool isThreadAlive( ThreadId id ) { HANDLE h = ::OpenThread( SYNCHRONIZE, FALSE, id ); if ( h == NULL ) @@ -26,6 +35,10 @@ namespace cds { namespace OS { } } // namespace Win32 + using Win32::ThreadId; + CDS_CONSTEXPR const ThreadId c_NullThreadId = 0; + + using Win32::getCurrentThreadId; using Win32::isThreadAlive; using Win32::backoff; diff --git a/cds/urcu/details/base.h b/cds/urcu/details/base.h index dcbfe2e4..0ba1359c 100644 --- a/cds/urcu/details/base.h +++ b/cds/urcu/details/base.h @@ -316,11 +316,11 @@ namespace cds { template struct thread_list_record { ThreadData * m_pNext ; ///< Next item in thread list - CDS_ATOMIC::atomic m_idOwner; ///< Owner thread id; 0 - the record is free (not owned) + CDS_ATOMIC::atomic m_idOwner ; ///< Owner thread id; 0 - the record is free (not owned) thread_list_record() : m_pNext( nullptr ) - , m_idOwner( std::thread::id() ) + , m_idOwner( cds::OS::c_NullThreadId ) {} ~thread_list_record() @@ -351,12 +351,12 @@ namespace cds { thread_record * alloc() { thread_record * pRec; - std::thread::id const nullThreadId = std::thread::id(); - std::thread::id const curThreadId = std::this_thread::get_id(); + cds::OS::ThreadId const nullThreadId = cds::OS::c_NullThreadId; + cds::OS::ThreadId const curThreadId = cds::OS::getCurrentThreadId(); // First try to reuse a retired (non-active) HP record for ( pRec = m_pHead.load( CDS_ATOMIC::memory_order_acquire ); pRec; pRec = pRec->m_list.m_pNext ) { - std::thread::id thId = nullThreadId; + cds::OS::ThreadId thId = nullThreadId; if ( !pRec->m_list.m_idOwner.compare_exchange_strong( thId, curThreadId, CDS_ATOMIC::memory_order_seq_cst, CDS_ATOMIC::memory_order_relaxed ) ) continue; return pRec; @@ -380,13 +380,13 @@ namespace cds { void retire( thread_record * pRec ) { assert( pRec != nullptr ); - pRec->m_list.m_idOwner.store( std::thread::id(), CDS_ATOMIC::memory_order_release ); + pRec->m_list.m_idOwner.store( cds::OS::c_NullThreadId, CDS_ATOMIC::memory_order_release ); } void detach_all() { thread_record * pNext = nullptr; - std::thread::id const nullThreadId = std::thread::id(); + cds::OS::ThreadId const nullThreadId = cds::OS::c_NullThreadId; for ( thread_record * pRec = m_pHead.load(CDS_ATOMIC::memory_order_acquire); pRec; pRec = pNext ) { pNext = pRec->m_list.m_pNext; @@ -405,8 +405,8 @@ namespace cds { void destroy() { allocator_type al; - CDS_DEBUG_DO( std::thread::id const nullThreadId = std::thread::id(); ) - CDS_DEBUG_DO( std::thread::id const mainThreadId = std::this_thread::get_id(); ) + CDS_DEBUG_DO( cds::OS::ThreadId const nullThreadId = cds::OS::c_NullThreadId; ) + CDS_DEBUG_DO( cds::OS::ThreadId const mainThreadId = cds::OS::getCurrentThreadId() ;) thread_record * p = m_pHead.exchange( nullptr, CDS_ATOMIC::memory_order_seq_cst ); while ( p ) { diff --git a/cds/urcu/details/gp.h b/cds/urcu/details/gp.h index d04c22ff..181e22ac 100644 --- a/cds/urcu/details/gp.h +++ b/cds/urcu/details/gp.h @@ -82,7 +82,7 @@ namespace cds { namespace urcu { namespace details { template inline void gp_singleton::flip_and_wait( Backoff& bkoff ) { - std::thread::id const nullThreadId = std::thread::id(); + OS::ThreadId const nullThreadId = OS::c_NullThreadId; m_nGlobalControl.fetch_xor( general_purpose_rcu::c_nControlBit, CDS_ATOMIC::memory_order_seq_cst ); for ( thread_record * pRec = m_ThreadList.head( CDS_ATOMIC::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) { diff --git a/cds/urcu/details/sh.h b/cds/urcu/details/sh.h index b39612b7..25e5642e 100644 --- a/cds/urcu/details/sh.h +++ b/cds/urcu/details/sh.h @@ -105,7 +105,7 @@ namespace cds { namespace urcu { namespace details { } template - inline void sh_singleton::raise_signal( std::thread::id tid ) + inline void sh_singleton::raise_signal( cds::OS::ThreadId tid ) { pthread_kill( tid, m_nSigNo ); } @@ -114,11 +114,11 @@ namespace cds { namespace urcu { namespace details { template inline void sh_singleton::force_membar_all_threads( Backoff& bkOff ) { - std::thread::id const nullThreadId = std::thread::id(); + OS::ThreadId const nullThreadId = OS::c_NullThreadId; // Send "need membar" signal to all RCU threads for ( thread_record * pRec = m_ThreadList.head( CDS_ATOMIC::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) { - std::thread::id tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire); + OS::ThreadId tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire); if ( tid != nullThreadId ) { pRec->m_bNeedMemBar.store( true, CDS_ATOMIC::memory_order_release ); raise_signal( tid ); @@ -127,7 +127,7 @@ namespace cds { namespace urcu { namespace details { // Wait while all RCU threads process the signal for ( thread_record * pRec = m_ThreadList.head( CDS_ATOMIC::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) { - std::thread::id tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire); + OS::ThreadId tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire); if ( tid != nullThreadId ) { bkOff.reset(); while ( (tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire )) != nullThreadId @@ -154,7 +154,7 @@ namespace cds { namespace urcu { namespace details { template void sh_singleton::wait_for_quiescent_state( Backoff& bkOff ) { - std::thread::id const nullThreadId = std::thread::id(); + OS::ThreadId const nullThreadId = OS::c_NullThreadId; for ( thread_record * pRec = m_ThreadList.head( CDS_ATOMIC::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) { while ( pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire) != nullThreadId && check_grace_period( pRec )) diff --git a/cds/urcu/details/sh_decl.h b/cds/urcu/details/sh_decl.h index 4789a87c..1386e606 100644 --- a/cds/urcu/details/sh_decl.h +++ b/cds/urcu/details/sh_decl.h @@ -159,7 +159,7 @@ namespace cds { namespace urcu { namespace details { void set_signal_handler(); void clear_signal_handler(); static void signal_handler( int signo, siginfo_t * sigInfo, void * context ); - void raise_signal( std::thread::id tid ); + void raise_signal( cds::OS::ThreadId tid ); template void force_membar_all_threads( Backoff& bkOff ); diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 113665ea..1fc9b85c 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -13,8 +13,8 @@ # endif #endif -static std::thread::id s_MainThreadId = 0; -static HINSTANCE s_DllInstance = NULL; +static cds::OS::ThreadId s_MainThreadId = 0; +static HINSTANCE s_DllInstance = NULL; #if _WIN32_WINNT < 0x0601 // For Windows below Windows 7 @@ -191,7 +191,7 @@ BOOL WINAPI DllMain( switch ( fdwReason ) { case DLL_PROCESS_ATTACH: s_DllInstance = hinstDLL; - s_MainThreadId = std::this_thread::get_id(); + s_MainThreadId = cds::OS::getCurrentThreadId(); #if _WIN32_WINNT < 0x0601 discover_topology(); #endif diff --git a/src/hrc_gc.cpp b/src/hrc_gc.cpp index 9033fdc6..12a37df6 100644 --- a/src/hrc_gc.cpp +++ b/src/hrc_gc.cpp @@ -38,7 +38,7 @@ namespace cds { namespace gc { { thread_list_node * pNode = m_pListHead.load( CDS_ATOMIC::memory_order_relaxed ); while ( pNode ) { - assert( pNode->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == std::thread::id() ); + assert( pNode->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == cds::OS::c_NullThreadId ); clearHRCThreadDesc( pNode ); thread_list_node * pNext = pNode->m_pNext; deleteHRCThreadDesc( pNode ); @@ -115,7 +115,7 @@ namespace cds { namespace gc { GarbageCollector::thread_list_node * GarbageCollector::getHRCThreadDescForCurrentThread() const { thread_list_node * hprec; - const std::thread::id curThreadId = std::this_thread::get_id(); + const cds::OS::ThreadId curThreadId = cds::OS::getCurrentThreadId(); for ( hprec = m_pListHead.load( CDS_ATOMIC::memory_order_acquire ); hprec; hprec = hprec->m_pNext ) { if ( hprec->m_idOwner.load( CDS_ATOMIC::memory_order_acquire ) == curThreadId ) { @@ -131,12 +131,12 @@ namespace cds { namespace gc { CDS_HRC_STATISTIC( ++m_Stat.m_AllocHRCThreadDesc ); thread_list_node * hprec; - const std::thread::id nullThreadId = std::thread::id(); - const std::thread::id curThreadId = std::this_thread::get_id(); + const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; + const cds::OS::ThreadId curThreadId = cds::OS::getCurrentThreadId(); // First try to reuse a retired (non-active) HP record for ( hprec = m_pListHead.load( CDS_ATOMIC::memory_order_acquire ); hprec; hprec = hprec->m_pNext ) { - std::thread::id expectedThreadId = nullThreadId; + cds::OS::ThreadId expectedThreadId = nullThreadId; if ( !hprec->m_idOwner.compare_exchange_strong( expectedThreadId, curThreadId, CDS_ATOMIC::memory_order_acq_rel, CDS_ATOMIC::memory_order_relaxed ) ) continue; hprec->m_pOwner = pThreadGC; @@ -172,13 +172,13 @@ namespace cds { namespace gc { assert( pNode->m_hzp.size() == pNode->m_hzp.capacity() ); /* It is possible that - pNode->m_idOwner.value() != std::this_thread::get_id() + pNode->m_idOwner.value() != cds::OS::getCurrentThreadId() if the destruction of thread object is called by the destructor after thread termination */ - assert( pNode->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) != std::thread::id() ); + assert( pNode->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) != cds::OS::c_NullThreadId ); pNode->m_pOwner = nullptr; - pNode->m_idOwner.store( std::thread::id(), CDS_ATOMIC::memory_order_release ); + pNode->m_idOwner.store( cds::OS::c_NullThreadId, CDS_ATOMIC::memory_order_release ); assert( pNode->m_hzp.size() == pNode->m_hzp.capacity() ); } @@ -189,7 +189,7 @@ namespace cds { namespace gc { typedef std::vector< ContainerNode * > hazard_ptr_list; details::thread_descriptor * pRec = pThreadGC->m_pDesc; - assert( static_cast< thread_list_node *>(pRec)->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == std::this_thread::get_id() ); + assert( static_cast< thread_list_node *>( pRec )->m_idOwner.load(CDS_ATOMIC::memory_order_relaxed) == cds::OS::getCurrentThreadId() ); // Step 1: mark all pRec->m_arrRetired items as "traced" { @@ -277,13 +277,13 @@ namespace cds { namespace gc { CDS_HRC_STATISTIC( ++m_Stat.m_HelpScanCalls ); - const std::thread::id nullThreadId = std::thread::id(); - const std::thread::id curThreadId = std::this_thread::get_id(); + const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; + const cds::OS::ThreadId curThreadId = cds::OS::getCurrentThreadId(); for ( thread_list_node * pRec = m_pListHead.load(CDS_ATOMIC::memory_order_acquire); pRec; pRec = pRec->m_pNext ) { // If threadDesc is free then own its - std::thread::id expectedThreadId = nullThreadId; + cds::OS::ThreadId expectedThreadId = nullThreadId; if ( !pRec->m_idOwner.compare_exchange_strong(expectedThreadId, curThreadId, CDS_ATOMIC::memory_order_acquire, CDS_ATOMIC::memory_order_relaxed) ) { continue; @@ -329,7 +329,7 @@ namespace cds { namespace gc { { CDS_HRC_STATISTIC( ++m_Stat.m_CleanUpAllCalls ); - //const std::thread::id nullThreadId = std::thread::id(); + //const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; thread_list_node * pThread = m_pListHead.load(CDS_ATOMIC::memory_order_acquire); while ( pThread ) { for ( size_t i = 0; i < pThread->m_arrRetired.capacity(); ++i ) { diff --git a/src/hzp_gc.cpp b/src/hzp_gc.cpp index 46d73153..5c0be168 100644 --- a/src/hzp_gc.cpp +++ b/src/hzp_gc.cpp @@ -58,8 +58,8 @@ namespace cds { namespace gc { GarbageCollector::~GarbageCollector() { - CDS_DEBUG_DO( const std::thread::id nullThreadId = std::thread::id(); ) - CDS_DEBUG_DO( const std::thread::id mainThreadId = std::this_thread::get_id(); ) + CDS_DEBUG_DO( const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; ) + CDS_DEBUG_DO( const cds::OS::ThreadId mainThreadId = cds::OS::getCurrentThreadId() ;) hplist_node * pHead = m_pListHead.load( CDS_ATOMIC::memory_order_relaxed ); m_pListHead.store( nullptr, CDS_ATOMIC::memory_order_relaxed ); @@ -108,12 +108,12 @@ namespace cds { namespace gc { CDS_HAZARDPTR_STATISTIC( ++m_Stat.m_AllocHPRec ); hplist_node * hprec; - const std::thread::id nullThreadId = std::thread::id(); - const std::thread::id curThreadId = std::this_thread::get_id(); + const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; + const cds::OS::ThreadId curThreadId = cds::OS::getCurrentThreadId(); // First try to reuse a retired (non-active) HP record for ( hprec = m_pListHead.load( CDS_ATOMIC::memory_order_acquire ); hprec; hprec = hprec->m_pNextNode ) { - std::thread::id thId = nullThreadId; + cds::OS::ThreadId thId = nullThreadId; if ( !hprec->m_idOwner.compare_exchange_strong( thId, curThreadId, CDS_ATOMIC::memory_order_seq_cst, CDS_ATOMIC::memory_order_relaxed ) ) continue; hprec->m_bFree.store( false, CDS_ATOMIC::memory_order_release ); @@ -144,13 +144,13 @@ namespace cds { namespace gc { pRec->clear(); Scan( pRec ); hplist_node * pNode = static_cast( pRec ); - pNode->m_idOwner.store( std::thread::id(), CDS_ATOMIC::memory_order_release ); + pNode->m_idOwner.store( cds::OS::c_NullThreadId, CDS_ATOMIC::memory_order_release ); } void GarbageCollector::detachAllThread() { hplist_node * pNext = NULL; - const std::thread::id nullThreadId = std::thread::id(); + const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; for ( hplist_node * hprec = m_pListHead.load(CDS_ATOMIC::memory_order_acquire); hprec; hprec = pNext ) { pNext = hprec->m_pNextNode; if ( hprec->m_idOwner.load(CDS_ATOMIC::memory_order_relaxed) != nullThreadId ) { @@ -269,10 +269,10 @@ namespace cds { namespace gc { { CDS_HAZARDPTR_STATISTIC( ++m_Stat.m_HelpScanCallCount ); - assert( static_cast(pThis)->m_idOwner.load( CDS_ATOMIC::memory_order_relaxed ) == std::this_thread::get_id() ); + assert( static_cast(pThis)->m_idOwner.load(CDS_ATOMIC::memory_order_relaxed) == cds::OS::getCurrentThreadId() ); - const std::thread::id nullThreadId = std::thread::id(); - const std::thread::id curThreadId = std::this_thread::get_id(); + const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; + const cds::OS::ThreadId curThreadId = cds::OS::getCurrentThreadId(); for ( hplist_node * hprec = m_pListHead.load(CDS_ATOMIC::memory_order_acquire); hprec; hprec = hprec->m_pNextNode ) { // If m_bFree == true then hprec->m_arrRetired is empty - we don't need to see it @@ -282,7 +282,7 @@ namespace cds { namespace gc { // Owns hprec if it is empty. // Several threads may work concurrently so we use atomic technique only. { - std::thread::id curOwner = hprec->m_idOwner.load( CDS_ATOMIC::memory_order_acquire ); + cds::OS::ThreadId curOwner = hprec->m_idOwner.load(CDS_ATOMIC::memory_order_acquire); if ( curOwner == nullThreadId || !cds::OS::isThreadAlive( curOwner )) { if ( !hprec->m_idOwner.compare_exchange_strong( curOwner, curThreadId, CDS_ATOMIC::memory_order_release, CDS_ATOMIC::memory_order_relaxed )) continue; diff --git a/tests/unit/map2/map_insdel_func.cpp b/tests/unit/map2/map_insdel_func.cpp index 4efef53d..d47a6bea 100644 --- a/tests/unit/map2/map_insdel_func.cpp +++ b/tests/unit/map2/map_insdel_func.cpp @@ -33,7 +33,7 @@ namespace map2 { size_t nData; CDS_ATOMIC::atomic nEnsureCall; CDS_ATOMIC::atomic bInitialized; - std::thread::id threadId; // insert thread id + cds::OS::ThreadId threadId ; // insert thread id typedef cds::lock::Spinlock< cds::backoff::pause > lock_type; mutable lock_type m_access; @@ -43,7 +43,7 @@ namespace map2 { , nData(0) , nEnsureCall(0) , bInitialized( false ) - , threadId( std::this_thread::get_id() ) + , threadId( cds::OS::getCurrentThreadId() ) {} value_type( value_type const& s ) @@ -51,7 +51,7 @@ namespace map2 { , nData(s.nData) , nEnsureCall(s.nEnsureCall.load(CDS_ATOMIC::memory_order_relaxed)) , bInitialized( s.bInitialized.load(CDS_ATOMIC::memory_order_relaxed) ) - , threadId( std::this_thread::get_id() ) + , threadId( cds::OS::getCurrentThreadId() ) {} // boost::container::flat_map requires operator = diff --git a/tests/unit/set2/set_insdel_func.h b/tests/unit/set2/set_insdel_func.h index c3a6df65..1f0bdf7d 100644 --- a/tests/unit/set2/set_insdel_func.h +++ b/tests/unit/set2/set_insdel_func.h @@ -28,9 +28,9 @@ namespace set2 { struct value_type { size_t nKey; size_t nData; - CDS_ATOMIC::atomic nEnsureCall; - bool volatile bInitialized; - std::thread::id threadId; // insert thread id + CDS_ATOMIC::atomic nEnsureCall; + bool volatile bInitialized; + cds::OS::ThreadId threadId ; // insert thread id typedef cds::lock::Spinlock< cds::backoff::pause > lock_type; mutable lock_type m_access; @@ -40,7 +40,7 @@ namespace set2 { , nData(0) , nEnsureCall(0) , bInitialized( false ) - , threadId( std::this_thread::get_id() ) + , threadId( cds::OS::getCurrentThreadId() ) {} value_type( value_type const& s ) @@ -48,7 +48,7 @@ namespace set2 { , nData(s.nData) , nEnsureCall(s.nEnsureCall.load(CDS_ATOMIC::memory_order_relaxed)) , bInitialized( s.bInitialized ) - , threadId( std::this_thread::get_id() ) + , threadId( cds::OS::getCurrentThreadId() ) {} // boost::container::flat_map requires operator =