Merge branch 'check' into dev
[libcds.git] / cds / urcu / details / sh.h
index b39612b7fe71d8fddd916decbc3b730abfb333b2..48ba977785528698d67e8a153db0358348c2b678 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef _CDS_URCU_DETAILS_SH_H
 #define _CDS_URCU_DETAILS_SH_H
 
+#include <memory.h> //memset
 #include <cds/urcu/details/sh_decl.h>
 
 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
@@ -39,15 +40,15 @@ namespace cds { namespace urcu { namespace details {
         thread_record * pRec = get_thread_record();
         assert( pRec != nullptr );
 
-        uint32_t tmp = pRec->m_nAccessControl.load( CDS_ATOMIC::memory_order_relaxed );
+        uint32_t tmp = pRec->m_nAccessControl.load( atomics::memory_order_relaxed );
         if ( (tmp & rcu_class::c_nNestMask) == 0 ) {
             pRec->m_nAccessControl.store(
-                sh_singleton<RCUtag>::instance()->global_control_word(CDS_ATOMIC::memory_order_acquire),
-                CDS_ATOMIC::memory_order_release
+                sh_singleton<RCUtag>::instance()->global_control_word(atomics::memory_order_acquire),
+                atomics::memory_order_release
             );
         }
         else {
-            pRec->m_nAccessControl.fetch_add( 1, CDS_ATOMIC::memory_order_release );
+            pRec->m_nAccessControl.fetch_add( 1, atomics::memory_order_release );
         }
         CDS_COMPILER_RW_BARRIER;
     }
@@ -59,7 +60,7 @@ namespace cds { namespace urcu { namespace details {
         assert( pRec != nullptr);
 
         CDS_COMPILER_RW_BARRIER;
-        pRec->m_nAccessControl.fetch_sub( 1, CDS_ATOMIC::memory_order_release );
+        pRec->m_nAccessControl.fetch_sub( 1, atomics::memory_order_release );
     }
 
     template <typename RCUtag>
@@ -68,7 +69,7 @@ namespace cds { namespace urcu { namespace details {
         thread_record * pRec = get_thread_record();
         assert( pRec != nullptr);
 
-        return (pRec->m_nAccessControl.load( CDS_ATOMIC::memory_order_relaxed ) & rcu_class::c_nNestMask) != 0;
+        return (pRec->m_nAccessControl.load( atomics::memory_order_relaxed ) & rcu_class::c_nNestMask) != 0;
     }
 
 
@@ -86,7 +87,7 @@ namespace cds { namespace urcu { namespace details {
         sigaction( m_nSigNo, &sigact, nullptr );
 
         sigaddset( &sigact.sa_mask, m_nSigNo );
-        pthread_sigmask( SIG_UNBLOCK, &sigact.sa_mask, NULL );
+        pthread_sigmask( SIG_UNBLOCK, &sigact.sa_mask, nullptr );
     }
 
     template <typename RCUtag>
@@ -94,18 +95,18 @@ namespace cds { namespace urcu { namespace details {
     {}
 
     template <typename RCUtag>
-    void sh_singleton<RCUtag>::signal_handler( int signo, siginfo_t * sigInfo, void * context )
+    void sh_singleton<RCUtag>::signal_handler( int /*signo*/, siginfo_t * /*sigInfo*/, void * /*context*/ )
     {
         thread_record * pRec = cds::threading::getRCU<RCUtag>();
         if ( pRec ) {
-            CDS_ATOMIC::atomic_signal_fence( CDS_ATOMIC::memory_order_acquire );
-            pRec->m_bNeedMemBar.store( false, CDS_ATOMIC::memory_order_relaxed );
-            CDS_ATOMIC::atomic_signal_fence( CDS_ATOMIC::memory_order_release );
+            atomics::atomic_signal_fence( atomics::memory_order_acquire );
+            pRec->m_bNeedMemBar.store( false, atomics::memory_order_relaxed );
+            atomics::atomic_signal_fence( atomics::memory_order_release );
         }
     }
 
     template <typename RCUtag>
-    inline void sh_singleton<RCUtag>::raise_signal( std::thread::id tid )
+    inline void sh_singleton<RCUtag>::raise_signal( cds::OS::ThreadId tid )
     {
         pthread_kill( tid, m_nSigNo );
     }
@@ -114,24 +115,24 @@ namespace cds { namespace urcu { namespace details {
     template <class Backoff>
     inline void sh_singleton<RCUtag>::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);
+        for ( thread_record * pRec = m_ThreadList.head( atomics::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) {
+            OS::ThreadId tid = pRec->m_list.m_idOwner.load( atomics::memory_order_acquire);
             if ( tid != nullThreadId ) {
-                pRec->m_bNeedMemBar.store( true, CDS_ATOMIC::memory_order_release );
+                pRec->m_bNeedMemBar.store( true, atomics::memory_order_release );
                 raise_signal( tid );
             }
         }
 
         // 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);
+        for ( thread_record * pRec = m_ThreadList.head( atomics::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) {
+            OS::ThreadId tid = pRec->m_list.m_idOwner.load( atomics::memory_order_acquire);
             if ( tid != nullThreadId ) {
                 bkOff.reset();
-                while ( (tid = pRec->m_list.m_idOwner.load( CDS_ATOMIC::memory_order_acquire )) != nullThreadId
-                     && pRec->m_bNeedMemBar.load( CDS_ATOMIC::memory_order_acquire ))
+                while ( (tid = pRec->m_list.m_idOwner.load( atomics::memory_order_acquire )) != nullThreadId
+                     && pRec->m_bNeedMemBar.load( atomics::memory_order_acquire ))
                 {
                     // Some versions of OSes can lose signals
                     // So, we resend the signal
@@ -145,19 +146,19 @@ namespace cds { namespace urcu { namespace details {
     template <typename RCUtag>
     bool sh_singleton<RCUtag>::check_grace_period( thread_record * pRec ) const
     {
-        uint32_t const v = pRec->m_nAccessControl.load( CDS_ATOMIC::memory_order_acquire );
+        uint32_t const v = pRec->m_nAccessControl.load( atomics::memory_order_acquire );
         return (v & signal_handling_rcu::c_nNestMask)
-            && ((( v ^ m_nGlobalControl.load( CDS_ATOMIC::memory_order_relaxed )) & ~signal_handling_rcu::c_nNestMask ));
+            && ((( v ^ m_nGlobalControl.load( atomics::memory_order_relaxed )) & ~signal_handling_rcu::c_nNestMask ));
     }
 
     template <typename RCUtag>
     template <class Backoff>
     void sh_singleton<RCUtag>::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 ))
+        for ( thread_record * pRec = m_ThreadList.head( atomics::memory_order_acquire); pRec; pRec = pRec->m_list.m_pNext ) {
+            while ( pRec->m_list.m_idOwner.load( atomics::memory_order_acquire) != nullThreadId && check_grace_period( pRec ))
                 bkOff();
         }
     }