bugfix in cds::gc::HP::guarded_ptr
[libcds.git] / tests / test-hdr / ordered_list / hdr_intrusive_michael.h
index ed76a10db99c2cd16fb52fa9c301a8b8333482bd..864dcc1e2595a39663d7bccb8d080780553e0847 100644 (file)
@@ -1,7 +1,7 @@
 //$$CDS-header$$
 
 #include "cppunit/cppunit_proxy.h"
-#include <cds/intrusive/michael_list_base.h>
+#include <cds/intrusive/details/michael_list_base.h>
 
 namespace ordlist {
     namespace ci = cds::intrusive;
@@ -223,7 +223,7 @@ namespace ordlist {
                 CPPUNIT_ASSERT( !l.find_with( v3.key(), less<value_type>() ));
                 CPPUNIT_ASSERT( !l.empty() );
 
-                CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is not raised since pNext is NULL
+                CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is not raised since pNext is nullptr
 
                 {
                     value_type v( v1 );
@@ -388,7 +388,13 @@ namespace ordlist {
                 // begin/end
                 {
                     typename OrdList::iterator it = l.begin();
+                    typename OrdList::const_iterator cit = l.cbegin();
                     CPPUNIT_ASSERT( it != l.end() );
+                    CPPUNIT_ASSERT( it != l.cend() );
+                    CPPUNIT_ASSERT( cit != l.end() );
+                    CPPUNIT_ASSERT( cit != l.cend() );
+                    CPPUNIT_ASSERT( cit == it );
+
                     CPPUNIT_ASSERT( it->nKey == v2.nKey );
                     CPPUNIT_ASSERT( it->nVal == v2.nVal );
                     CPPUNIT_ASSERT( ++it != l.end() );
@@ -451,7 +457,6 @@ namespace ordlist {
             static int const nLimit = 20;
             typename OrdList::value_type arrItem[nLimit];
 
-
             {
                 int a[nLimit];
                 for (int i = 0; i < nLimit; ++i)
@@ -468,27 +473,28 @@ namespace ordlist {
                     CPPUNIT_ASSERT( l.insert( arrItem[i] ) );
 
                 for ( int i=0; i < nLimit; ++i ) {
-                    CPPUNIT_ASSERT( l.get( gp, arrItem[i].nKey ));
+                    gp = l.get( arrItem[i].nKey );
+                    CPPUNIT_ASSERT_EX( gp, "i=" << i );
                     CPPUNIT_ASSERT( !gp.empty());
-                    CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
-                    CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
-                    gp.release();
+                    CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey );
+                    CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal );
 
-                    CPPUNIT_ASSERT( l.extract( gp, arrItem[i].nKey ));
+                    gp = l.extract( arrItem[i].nKey );
+                    CPPUNIT_ASSERT_EX( gp, "i=" << i );
                     CPPUNIT_ASSERT( !gp.empty());
-                    CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
-                    CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
-                    gp.release();
-
-                    CPPUNIT_ASSERT( !l.get( gp, arrItem[i].nKey ));
-                    CPPUNIT_ASSERT( gp.empty());
-                    CPPUNIT_ASSERT( !l.extract( gp, arrItem[i].nKey ));
-                    CPPUNIT_ASSERT( gp.empty());
+                    CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey );
+                    CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal );
+
+                    gp = l.get( arrItem[i].nKey );
+                    CPPUNIT_CHECK( !gp );
+                    CPPUNIT_CHECK( gp.empty());
+                    CPPUNIT_CHECK( !l.extract( arrItem[i].nKey ));
+                    CPPUNIT_CHECK( gp.empty());
                 }
                 CPPUNIT_ASSERT( l.empty() );
-                CPPUNIT_ASSERT( !l.get( gp, nLimit/2 ));
+                CPPUNIT_ASSERT( !l.get( nLimit/2 ));
                 CPPUNIT_ASSERT( gp.empty());
-                CPPUNIT_ASSERT( !l.extract( gp, nLimit/2 ));
+                CPPUNIT_ASSERT( !l.extract( nLimit/2 ));
                 CPPUNIT_ASSERT( gp.empty());
 
                 // Apply retired pointer
@@ -500,27 +506,28 @@ namespace ordlist {
 
                 for ( int i=0; i < nLimit; ++i ) {
                     other_item itm( arrItem[i].nKey );
-                    CPPUNIT_ASSERT( l.get_with( gp, itm, other_less() ));
+                    gp = l.get_with( itm, other_less() );
+                    CPPUNIT_ASSERT_EX( gp, "i=" << i );
                     CPPUNIT_ASSERT( !gp.empty());
-                    CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
-                    CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
-                    gp.release();
+                    CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey );
+                    CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal );
 
-                    CPPUNIT_ASSERT( l.extract_with( gp, itm, other_less() ));
+                    gp = l.extract_with( itm, other_less() );
+                    CPPUNIT_ASSERT_EX( gp, "i=" << i );
                     CPPUNIT_ASSERT( !gp.empty());
-                    CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
-                    CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
-                    gp.release();
-
-                    CPPUNIT_ASSERT( !l.get_with( gp, itm, other_less() ));
-                    CPPUNIT_ASSERT( gp.empty());
-                    CPPUNIT_ASSERT( !l.extract_with( gp, itm, other_less() ));
-                    CPPUNIT_ASSERT( gp.empty());
+                    CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey );
+                    CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal );
+
+                    gp = l.get_with( itm, other_less() );
+                    CPPUNIT_CHECK( !gp );
+                    CPPUNIT_CHECK( gp.empty());
+                    CPPUNIT_CHECK( !l.extract_with( itm, other_less() ));
+                    CPPUNIT_CHECK( gp.empty());
                 }
                 CPPUNIT_ASSERT( l.empty() );
-                CPPUNIT_ASSERT( !l.get_with( gp, other_item(nLimit/2), other_less() ));
+                CPPUNIT_ASSERT( !l.get_with( other_item(nLimit/2), other_less() ));
                 CPPUNIT_ASSERT( gp.empty());
-                CPPUNIT_ASSERT( !l.extract_with( gp, other_item(nLimit/2), other_less() ));
+                CPPUNIT_ASSERT( !l.extract_with( other_item(nLimit/2), other_less() ));
                 CPPUNIT_ASSERT( gp.empty());
 
                 // Apply retired pointer
@@ -564,13 +571,16 @@ namespace ordlist {
 
                 for ( int i = 0; i < nLimit; ++i ) {
                     {
-                        rcu_lock lock;
-                        value_type * pGet = l.get( a[i] );
-                        CPPUNIT_ASSERT( pGet != NULL );
-                        CPPUNIT_CHECK( pGet->nKey == a[i] );
-                        CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
-
-                        CPPUNIT_ASSERT( l.extract( ep, a[i] ));
+                        {
+                            rcu_lock lock;
+                            value_type * pGet = l.get( a[i] );
+                            CPPUNIT_ASSERT( pGet != nullptr );
+                            CPPUNIT_CHECK( pGet->nKey == a[i] );
+                            CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
+                        }
+
+                        ep = l.extract( a[i] );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == a[i] );
                         CPPUNIT_CHECK( (*ep).nVal == a[i] * 2 );
@@ -578,8 +588,8 @@ namespace ordlist {
                     ep.release();
                     {
                         rcu_lock lock;
-                        CPPUNIT_CHECK( l.get( a[i]) == NULL );
-                        CPPUNIT_CHECK( !l.extract( ep, a[i] ));
+                        CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
+                        CPPUNIT_CHECK( !l.extract( a[i] ));
                         CPPUNIT_CHECK( ep.empty() );
                     }
                 }
@@ -587,8 +597,9 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get( a[0] ) == NULL );
-                    CPPUNIT_CHECK( !l.extract( ep, a[0] ) );
+                    CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
+                    ep = l.extract( a[0] );
+                    CPPUNIT_CHECK( !ep );
                     CPPUNIT_CHECK( ep.empty() );
                 }
                 // Apply retired pointer
@@ -602,13 +613,16 @@ namespace ordlist {
                 for ( int i = 0; i < nLimit; ++i ) {
                     other_item itm( a[i] );
                     {
-                        rcu_lock lock;
-                        value_type * pGet = l.get_with( itm, other_less() );
-                        CPPUNIT_ASSERT( pGet != NULL );
-                        CPPUNIT_CHECK( pGet->nKey == a[i] );
-                        CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
-
-                        CPPUNIT_ASSERT( l.extract_with( ep, itm, other_less() ));
+                        {
+                            rcu_lock lock;
+                            value_type * pGet = l.get_with( itm, other_less() );
+                            CPPUNIT_ASSERT( pGet != nullptr );
+                            CPPUNIT_CHECK( pGet->nKey == a[i] );
+                            CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
+                        }
+
+                        ep = l.extract_with( itm, other_less() );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == a[i] );
                         CPPUNIT_CHECK( ep->nVal == a[i] * 2 );
@@ -616,8 +630,9 @@ namespace ordlist {
                     ep.release();
                     {
                         rcu_lock lock;
-                        CPPUNIT_CHECK( l.get_with( itm, other_less()) == NULL );
-                        CPPUNIT_CHECK( !l.extract_with( ep, itm, other_less() ));
+                        CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr );
+                        ep = l.extract_with( itm, other_less() );
+                        CPPUNIT_CHECK( !ep );
                         CPPUNIT_CHECK( ep.empty() );
                     }
                 }
@@ -625,8 +640,8 @@ namespace ordlist {
 
                 {
                     rcu_lock lock;
-                    CPPUNIT_CHECK( l.get_with( other_item(0), other_less() ) == NULL );
-                    CPPUNIT_CHECK( !l.extract_with( ep, other_item(0), other_less() ));
+                    CPPUNIT_CHECK( l.get_with( other_item( 0 ), other_less() ) == nullptr );
+                    CPPUNIT_CHECK( !l.extract_with( other_item(0), other_less() ));
                     CPPUNIT_CHECK( ep.empty() );
                 }
                 // Apply retired pointer
@@ -653,11 +668,11 @@ namespace ordlist {
                     CPPUNIT_ASSERT( l.find( v1.key(), find_functor() ));
                     CPPUNIT_ASSERT( v1.s.nFindCall == 1 );
 
-                    CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>() ) == NULL );
+                    CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>() ) == nullptr );
                     CPPUNIT_ASSERT( !l.find_with( v3.key(), less<value_type>(), find_functor() ));
                     CPPUNIT_ASSERT( !l.empty() );
 
-                    CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is not raised since pNext is NULL
+                    CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is not raised since pNext is nullptr
 
                     {
                         value_type v( v1 );
@@ -707,7 +722,13 @@ namespace ordlist {
 
                     {
                         typename OrdList::iterator it = l.begin();
+                        typename OrdList::const_iterator cit = l.cbegin();
                         CPPUNIT_ASSERT( it != l.end() );
+                        CPPUNIT_ASSERT( it != l.cend() );
+                        CPPUNIT_ASSERT( cit != l.end() );
+                        CPPUNIT_ASSERT( cit != l.cend() );
+                        CPPUNIT_ASSERT( cit == it );
+
                         CPPUNIT_ASSERT( it->nKey == v2.nKey );
                         CPPUNIT_ASSERT( it->nVal == v2.nVal );
                         CPPUNIT_ASSERT( ++it != l.end() );
@@ -753,19 +774,14 @@ namespace ordlist {
         void HP_member_cmpmix();
         void HP_member_ic();
 
-        void PTB_base_cmp();
-        void PTB_base_less();
-        void PTB_base_cmpmix();
-        void PTB_base_ic();
-        void PTB_member_cmp();
-        void PTB_member_less();
-        void PTB_member_cmpmix();
-        void PTB_member_ic();
-
-        void HRC_base_cmp();
-        void HRC_base_less();
-        void HRC_base_cmpmix();
-        void HRC_base_ic();
+        void DHP_base_cmp();
+        void DHP_base_less();
+        void DHP_base_cmpmix();
+        void DHP_base_ic();
+        void DHP_member_cmp();
+        void DHP_member_less();
+        void DHP_member_cmpmix();
+        void DHP_member_ic();
 
         void RCU_GPI_base_cmp();
         void RCU_GPI_base_less();
@@ -832,19 +848,14 @@ namespace ordlist {
             CPPUNIT_TEST(HP_member_cmpmix)
             CPPUNIT_TEST(HP_member_ic)
 
-            CPPUNIT_TEST(PTB_base_cmp)
-            CPPUNIT_TEST(PTB_base_less)
-            CPPUNIT_TEST(PTB_base_cmpmix)
-            CPPUNIT_TEST(PTB_base_ic)
-            CPPUNIT_TEST(PTB_member_cmp)
-            CPPUNIT_TEST(PTB_member_less)
-            CPPUNIT_TEST(PTB_member_cmpmix)
-            CPPUNIT_TEST(PTB_member_ic)
-
-            CPPUNIT_TEST(HRC_base_cmp)
-            CPPUNIT_TEST(HRC_base_less)
-            CPPUNIT_TEST(HRC_base_cmpmix)
-            CPPUNIT_TEST(HRC_base_ic)
+            CPPUNIT_TEST(DHP_base_cmp)
+            CPPUNIT_TEST(DHP_base_less)
+            CPPUNIT_TEST(DHP_base_cmpmix)
+            CPPUNIT_TEST(DHP_base_ic)
+            CPPUNIT_TEST(DHP_member_cmp)
+            CPPUNIT_TEST(DHP_member_less)
+            CPPUNIT_TEST(DHP_member_cmpmix)
+            CPPUNIT_TEST(DHP_member_ic)
 
             CPPUNIT_TEST(RCU_GPI_base_cmp)
             CPPUNIT_TEST(RCU_GPI_base_less)