2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H
32 #define CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H
34 #include "test_intrusive_set.h"
36 // forward declaration
37 namespace cds { namespace intrusive {}}
41 namespace ci = cds::intrusive;
42 namespace co = cds::opt;
44 class intrusive_set_rcu: public intrusive_set
46 typedef intrusive_set base_class;
53 // Precondition: set is empty
54 // Postcondition: set is empty
56 base_class::test( s );
58 ASSERT_TRUE( s.empty() );
59 ASSERT_CONTAINER_SIZE( s, 0 );
61 typedef typename Set::value_type value_type;
63 std::vector< value_type > data;
64 std::vector< size_t> indices;
65 data.reserve( kSize );
66 indices.reserve( kSize );
67 for ( size_t key = 0; key < kSize; ++key ) {
68 data.push_back( value_type( static_cast<int>(key) ) );
69 indices.push_back( key );
71 shuffle( indices.begin(), indices.end() );
73 typename Set::exempt_ptr xp;
74 typename Set::raw_ptr rp;
75 typedef typename Set::rcu_lock rcu_lock;
77 // get/extract from empty set
78 for ( auto idx : indices ) {
85 rp = s.get( i.key() );
87 rp = s.get_with( other_item( i.key()), other_less());
91 if ( Set::c_bExtractLockExternal ) {
96 xp = s.extract( i.key() );
98 xp = s.extract_with( other_item( i.key() ), other_less() );
104 xp = s.extract( i.key() );
106 xp = s.extract_with( other_item( i.key() ), other_less() );
112 for ( auto& i : data ) {
114 ASSERT_TRUE( s.insert( i ) );
118 for ( auto idx : indices ) {
123 EXPECT_EQ( i.nFindCount, 0 );
127 EXPECT_EQ( i.nFindCount, 1 );
129 rp = s.get( i.key() );
132 EXPECT_EQ( i.nFindCount, 2 );
134 rp = s.get_with( other_item( i.key()), other_less());
137 EXPECT_EQ( i.nFindCount, 3 );
140 if ( Set::c_bExtractLockExternal ) {
143 EXPECT_EQ( i.nEraseCount, 0 );
144 switch ( i.key() % 3 ) {
146 xp = s.extract( i.key());
152 xp = s.extract_with( other_item( i.key() ), other_less() );
157 EXPECT_EQ( i.nEraseCount, 1 );
161 xp = s.extract( i.key() );
163 xp = s.extract_with( other_item( i.key() ), other_less() );
167 EXPECT_EQ( i.nEraseCount, 0 );
168 switch ( i.key() % 3 ) {
170 xp = s.extract( i.key());
176 xp = s.extract_with( other_item( i.key() ), other_less() );
181 EXPECT_EQ( i.nEraseCount, 1 );
185 xp = s.extract( i.key() );
187 xp = s.extract_with( other_item( i.key() ), other_less() );
192 ASSERT_TRUE( s.empty() );
193 ASSERT_CONTAINER_SIZE( s, 0 );
195 // Force retiring cycle
196 Set::gc::force_dispose();
197 for ( auto& i : data ) {
198 EXPECT_EQ( i.nDisposeCount, 1 );
203 } // namespace cds_test
205 #endif // #ifndef CDSUNIT_SET_TEST_INTRUSIVE_SET_RCU_H