Added TSan annotations
[libcds.git] / cds / memory / michael / allocator.h
index bc30dd1fa01a69ac2bd8aa533ca62d9423adbe3e..0271139504076b99a6f9d7b2e55414780b5d40c0 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
-#ifndef __CDS_MEMORY_MICHAEL_ALLOCATOR_TMPL_H
-#define __CDS_MEMORY_MICHAEL_ALLOCATOR_TMPL_H
+#ifndef CDSLIB_MEMORY_MICHAEL_ALLOCATOR_TMPL_H
+#define CDSLIB_MEMORY_MICHAEL_ALLOCATOR_TMPL_H
 
 /*
     Michael allocator implementation
@@ -60,7 +60,8 @@ namespace michael {
         /// Allocates memory block of \p nSize bytes (\p malloc wrapper)
         static void * alloc( size_t nSize )
         {
-            return ::malloc( nSize );
+            void * p = ::malloc( nSize );
+            return p;
         }
         /// Returning memory block to the system (\p free wrapper)
         static void free( void * p )
@@ -1222,7 +1223,11 @@ namespace michael {
 
                 assert( oldAnchor.avail < pDesc->nCapacity );
                 pAddr = pDesc->pSB + oldAnchor.avail * (unsigned long long) pDesc->nBlockSize;
+
+                // TSan reports data race if the block contained atomic ops before
+                CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                 newAnchor.avail = reinterpret_cast<free_block_header *>( pAddr )->nNextFree;
+                CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                 newAnchor.tag += 1;
 
                 if ( oldActive.credits() == 0 ) {
@@ -1450,6 +1455,9 @@ namespace michael {
 
             static_assert( (sizeof(processor_heap) % c_nAlignment) == 0, "sizeof(processor_heap) error" );
 
+            // TSan false positive: a new descriptor will be linked further with release fence
+            CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
+
             pDesc = new( m_AlignedHeap.alloc( szTotal, c_nAlignment ) ) processor_desc;
 
             pDesc->pageHeaps = reinterpret_cast<page_heap *>( pDesc + 1 );
@@ -1474,6 +1482,7 @@ namespace michael {
                 else
                     pProcHeap->nPageIdx = pProcHeap->pSizeClass->nSBSizeIdx;
             }
+            CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
             return pDesc;
         }
 
@@ -1681,6 +1690,7 @@ namespace michael {
                 );
             }
 
+            CDS_TSAN_ANNOTATE_NEW_MEMORY( pBlock + 1, nSize );
             return pBlock + 1;
         }
 
@@ -1893,4 +1903,4 @@ namespace michael {
 
 }}} // namespace cds::memory::michael
 
-#endif // __CDS_MEMORY_MICHAEL_ALLOCATOR_TMPL_H
+#endif // CDSLIB_MEMORY_MICHAEL_ALLOCATOR_TMPL_H