issue #76: added cds::atomicity::cache_friendly_item_counter to avoid false sharing
[libcds.git] / cds / container / details / bronson_avltree_base.h
index bb709fc45505b6199a4b6dafc881e5e55ee26e18..5230164570ada0d0a10b1e1762e5eb73a6f29aac 100644 (file)
@@ -1,11 +1,11 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -25,7 +25,7 @@
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSLIB_CONTAINER_DETAILS_BRONSON_AVLTREE_BASE_H
@@ -76,8 +76,9 @@ namespace cds { namespace container {
                 , m_pParent( nullptr )
                 , m_pLeft( nullptr )
                 , m_pRight( nullptr )
-                , m_pValue( nullptr )
-            {}
+            {
+                m_pValue.store( nullptr, atomics::memory_order_release );
+            }
 
             link_node( int nHeight, version_type version, node_type * pParent, node_type * pLeft, node_type * pRight )
                 : m_nHeight( nHeight )
@@ -85,8 +86,9 @@ namespace cds { namespace container {
                 , m_pParent( pParent )
                 , m_pLeft( pLeft )
                 , m_pRight( pRight )
-                , m_pValue( nullptr )
-            {}
+            {
+                m_pValue.store( nullptr, atomics::memory_order_release );
+            }
 
             node_type * parent( atomics::memory_order order ) const
             {
@@ -137,7 +139,7 @@ namespace cds { namespace container {
             void wait_until_shrink_completed( atomics::memory_order order ) const
             {
                 BackOff bkoff;
-                while ( is_shrinking( order ) )
+                while ( is_shrinking( order ))
                     bkoff();
             }
 
@@ -185,14 +187,14 @@ namespace cds { namespace container {
             template <typename Q>
             node( Q&& key )
                 : base_class()
-                , m_key( std::forward<Q>( key ) )
+                , m_key( std::forward<Q>( key ))
                 , m_pNextRemoved( nullptr )
             {}
 
             template <typename Q>
             node( Q&& key, int nHeight, version_type version, node * pParent, node * pLeft, node * pRight )
                 : base_class( nHeight, version, pParent, pLeft, pRight )
-                , m_key( std::forward<Q>( key ) )
+                , m_key( std::forward<Q>( key ))
                 , m_pNextRemoved( nullptr )
             {}
             //@endcond
@@ -438,7 +440,7 @@ namespace cds { namespace container {
             /// Item counter
             /**
                 The type for item counter, by default it is disabled (\p atomicity::empty_item_counter).
-                To enable it use \p atomicity::item_counter
+                To enable it use \p atomicity::item_counter or \p atomicity::cache_friendly_item_counter.
             */
             typedef atomicity::empty_item_counter     item_counter;
 
@@ -450,15 +452,15 @@ namespace cds { namespace container {
 
             /// Internal statistics
             /**
-                By default, internal statistics is disabled (\p ellen_bintree::empty_stat).
-                To enable it use \p ellen_bintree::stat.
+                By default, internal statistics is disabled (\p bronson_avltree::empty_stat).
+                To enable it use \p bronson_avltree::stat.
             */
             typedef empty_stat                      stat;
 
             /// Back-off strategy
             typedef cds::backoff::empty             back_off;
 
-            /// RCU deadlock checking policy (only for \ref cds_container_BronsonAVLTreeMap_rcu "RCU-based BronsonAVLTree")
+            /// RCU deadlock checking policy
             /**
                 List of available options see \p opt::rcu_check_deadlock
             */
@@ -491,7 +493,7 @@ namespace cds { namespace container {
             - \p bronson_avltree::relaxed_insert - enable (\p true) or disable (\p false, the default)
                 @ref bronson_avltree::relaxed_insert "relaxed insertion"
             - \p opt::item_counter - the type of item counting feature, by default it is disabled (\p atomicity::empty_item_counter)
-                To enable it use \p atomicity::item_counter
+                To enable it use \p atomicity::item_counter or \p atomicity::cache_friendly_item_counter
             - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
                 or \p opt::v::sequential_consistent (sequentially consisnent memory model).
             - \p opt::stat - internal statistics, by default it is disabled (\p bronson_avltree::empty_stat)