From 97438a7bbd946a95c9427fe03c366766e3c909b0 Mon Sep 17 00:00:00 2001
From: khizmax <libcds.dev@gmail.com>
Date: Fri, 15 May 2015 00:00:17 +0300
Subject: [PATCH] TSan exam: EllenBinTree, FCPriorityQueue

---
 cds/container/fcpriority_queue.h   | 5 +++++
 cds/intrusive/impl/ellen_bintree.h | 7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/cds/container/fcpriority_queue.h b/cds/container/fcpriority_queue.h
index c98f155b..163537ed 100644
--- a/cds/container/fcpriority_queue.h
+++ b/cds/container/fcpriority_queue.h
@@ -259,6 +259,9 @@ namespace cds { namespace container {
         {
             assert( pRec );
 
+            // this function is called under FC mutex, so switch TSan off
+            CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN;
+
             switch ( pRec->op() ) {
             case op_push:
                 assert( pRec->pValPush );
@@ -287,6 +290,8 @@ namespace cds { namespace container {
                 assert(false);
                 break;
             }
+
+            CDS_TSAN_ANNOTATE_IGNORE_RW_END;
         }
         //@endcond
     };
diff --git a/cds/intrusive/impl/ellen_bintree.h b/cds/intrusive/impl/ellen_bintree.h
index a3ae991b..c422c24c 100644
--- a/cds/intrusive/impl/ellen_bintree.h
+++ b/cds/intrusive/impl/ellen_bintree.h
@@ -1235,25 +1235,28 @@ namespace cds { namespace intrusive {
                 if ( nCmp < 0 ) {
                     if ( res.pGrandParent ) {
                         assert( !res.pLeaf->infinite_key() );
-                        pNewInternal->infinite_key( 0 );
                         // TSan false positive: there is the release fence below, pNewInternal is not linked yet
                         CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
+                        pNewInternal->infinite_key( 0 );
                         key_extractor()(pNewInternal->m_Key, *node_traits::to_value_ptr( res.pLeaf ));
                         CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                     }
                     else {
                         assert( res.pLeaf->infinite_key() == tree_node::key_infinite1 );
+                        // TSan false positive: there is the release fence below, pNewInternal is not linked yet
+                        CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                         pNewInternal->infinite_key( 1 );
+                        CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                     }
                     pNewInternal->m_pLeft.store( static_cast<tree_node *>(pNewLeaf), memory_model::memory_order_relaxed );
                     pNewInternal->m_pRight.store( static_cast<tree_node *>(res.pLeaf), memory_model::memory_order_release );
                 }
                 else {
                     assert( !res.pLeaf->is_internal() );
-                    pNewInternal->infinite_key( 0 );
 
                     // TSan false positive: there is the release fence below, pNewInternal is not linked yet
                     CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
+                    pNewInternal->infinite_key( 0 );
                     key_extractor()(pNewInternal->m_Key, val);
                     CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                     pNewInternal->m_pLeft.store( static_cast<tree_node *>(res.pLeaf), memory_model::memory_order_relaxed );
-- 
2.34.1