[TSan] Tuning memory order
authorkhizmax <libcds.dev@gmail.com>
Thu, 1 Dec 2016 19:35:00 +0000 (22:35 +0300)
committerkhizmax <libcds.dev@gmail.com>
Thu, 1 Dec 2016 19:35:00 +0000 (22:35 +0300)
cds/compiler/feature_tsan.h
cds/memory/michael/allocator.h
cds/urcu/details/base.h
src/hp_gc.cpp

index 2f700c6..3f6e67b 100644 (file)
@@ -51,6 +51,7 @@
                                                     CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;\
                                                     CDS_TSAN_ANNOTATE_IGNORE_READS_END
 #   define CDS_TSAN_ANNOTATE_NEW_MEMORY( addr, sz ) AnnotateNewMemory( __FILE__, __LINE__, reinterpret_cast<void *>(addr), sz )
+#   define CDS_TSAN_ANNOTATE_PUBLISH_MEMORY_RANGE( addr, sz ) AnnotatePublishMemoryRange( __FILE__, __LINE__, reinterpret_cast<void *>(addr), sz )
 
 #   define CDS_TSAN_ANNOTATE_MUTEX_CREATE( addr )    AnnotateRWLockCreate( __FILE__, __LINE__, reinterpret_cast<void *>(addr))
 #   define CDS_TSAN_ANNOTATE_MUTEX_DESTROY( addr )   AnnotateRWLockDestroy( __FILE__, __LINE__, reinterpret_cast<void *>(addr))
@@ -69,7 +70,8 @@
         void AnnotateIgnoreWritesBegin(const char *f, int l);
         void AnnotateIgnoreWritesEnd(const char *f, int l);
 
-        void AnnotateNewMemory( const char *f, int l, void * mem, size_t size);
+        void AnnotatePublishMemoryRange( const char *f, int l, void * mem, size_t size )
+        void AnnotateNewMemory( const char *f, int l, void * mem, size_t size );
 
         void AnnotateRWLockCreate( const char *f, int l, void* m );
         void AnnotateRWLockDestroy( const char *f, int l, void* m );
@@ -89,6 +91,7 @@
 #   define CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN
 #   define CDS_TSAN_ANNOTATE_IGNORE_RW_END
 
+#   define CDS_TSAN_ANNOTATE_PUBLISH_MEMORY_RANGE( addr, sz )
 #   define CDS_TSAN_ANNOTATE_NEW_MEMORY( addr, sz )
 
 #   define CDS_TSAN_ANNOTATE_MUTEX_CREATE( addr )
index 4ef0f6d..cdb12a3 100644 (file)
@@ -1703,7 +1703,7 @@ namespace michael {
                 );
             }
 
-            CDS_TSAN_ANNOTATE_NEW_MEMORY( pBlock + 1, nSize );
+            CDS_TSAN_ANNOTATE_PUBLISH_MEMORY_RANGE( pBlock + 1, nSize );
             return pBlock + 1;
         }
 
index 84bf8fb..21676d8 100644 (file)
@@ -375,12 +375,12 @@ namespace cds {
                     // No records available for reuse
                     // Allocate and push a new record
                     pRec = allocator_type().New( curThreadId );
-                    CDS_COMPILER_RW_BARRIER;
 
                     thread_record * pOldHead = m_pHead.load( atomics::memory_order_acquire );
                     do {
+                        // Compiler barriers: assignment MUST BE inside the loop
+                        CDS_COMPILER_RW_BARRIER;
                         pRec->m_list.m_pNext = pOldHead;
-                        // Compiler barrier: assignment above MUST BE inside the loop
                         CDS_COMPILER_RW_BARRIER;
                     } while ( !m_pHead.compare_exchange_weak( pOldHead, pRec, atomics::memory_order_acq_rel, atomics::memory_order_acquire ));
 
index 08043f4..15bd2b6 100644 (file)
@@ -145,12 +145,12 @@ namespace cds { namespace gc {
             // No HP records available for reuse
             // Allocate and push a new HP record
             hprec = NewHPRec( curThreadId );
-            CDS_COMPILER_RW_BARRIER;
 
             hplist_node * pOldHead = m_pListHead.load( atomics::memory_order_acquire );
             do {
+                // Compiler barriers: assignment MUST BE inside the loop
+                CDS_COMPILER_RW_BARRIER;
                 hprec->m_pNextNode = pOldHead;
-                // Compiler barrier: assignment above MUST BE inside the loop
                 CDS_COMPILER_RW_BARRIER;
             } while ( !m_pListHead.compare_exchange_weak( pOldHead, hprec, atomics::memory_order_acq_rel, atomics::memory_order_acquire ));