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 #include "test_intrusive_msqueue.h"
33 #include <cds/gc/hp.h>
34 #include <cds/intrusive/basket_queue.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::HP gc_type;
42 class IntrusiveBasketQueue_HP : public cds_test::intrusive_msqueue
44 typedef cds_test::intrusive_msqueue base_class;
47 typedef typename base_class::base_hook_item< ci::basket_queue::node<gc_type>> base_item_type;
48 typedef typename base_class::member_hook_item< ci::basket_queue::node<gc_type>> member_item_type;
52 typedef ci::BasketQueue< gc_type, base_item_type > queue_type;
54 cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 );
55 cds::threading::Manager::attachThread();
60 cds::threading::Manager::detachThread();
61 cds::gc::hp::GarbageCollector::Destruct( true );
65 void check_array( V& arr )
67 for ( size_t i = 0; i < arr.size() - 1; ++i ) {
68 ASSERT_EQ( arr[i].nDisposeCount, 2 );
70 ASSERT_EQ( arr.back().nDisposeCount, 1 );
74 TEST_F( IntrusiveBasketQueue_HP, defaulted )
76 typedef cds::intrusive::BasketQueue< gc_type, base_item_type,
77 typename ci::basket_queue::make_traits<
78 ci::opt::disposer< mock_disposer >
82 std::vector<base_item_type> arr;
92 TEST_F( IntrusiveBasketQueue_HP, base_hook )
94 typedef cds::intrusive::BasketQueue< gc_type, base_item_type,
95 typename ci::basket_queue::make_traits<
96 ci::opt::disposer< mock_disposer >
97 ,ci::opt::hook< ci::basket_queue::base_hook< ci::opt::gc<gc_type>>>
101 std::vector<base_item_type> arr;
111 TEST_F( IntrusiveBasketQueue_HP, base_item_counting )
113 typedef cds::intrusive::BasketQueue< gc_type, base_item_type,
114 typename ci::basket_queue::make_traits<
115 ci::opt::disposer< mock_disposer >
116 , cds::opt::item_counter< cds::atomicity::item_counter >
117 , ci::opt::hook< ci::basket_queue::base_hook< ci::opt::gc<gc_type>>>
121 std::vector<base_item_type> arr;
131 TEST_F( IntrusiveBasketQueue_HP, base_stat )
133 struct traits : public ci::basket_queue::traits
135 typedef mock_disposer disposer;
136 typedef cds::atomicity::item_counter item_counter;
137 typedef ci::basket_queue::stat<> stat;
138 typedef cds::opt::v::sequential_consistent memory_model;
140 typedef cds::intrusive::BasketQueue< gc_type, base_item_type, traits > test_queue;
142 std::vector<base_item_type> arr;
152 TEST_F( IntrusiveBasketQueue_HP, member_hook )
154 typedef cds::intrusive::BasketQueue< gc_type, member_item_type,
155 typename ci::basket_queue::make_traits<
156 ci::opt::disposer< mock_disposer >
157 ,ci::opt::hook< ci::basket_queue::member_hook<
158 offsetof( member_item_type, hMember ),
164 std::vector<member_item_type> arr;
174 TEST_F( IntrusiveBasketQueue_HP, member_hook_stat )
176 struct traits : public ci::basket_queue::traits
178 typedef ci::basket_queue::member_hook<
179 offsetof( member_item_type, hMember ),
182 typedef mock_disposer disposer;
183 typedef cds::atomicity::item_counter item_counter;
184 typedef ci::basket_queue::stat<> stat;
185 typedef cds::opt::v::sequential_consistent memory_model;
187 typedef cds::intrusive::BasketQueue< gc_type, member_item_type, traits > test_queue;
189 std::vector<member_item_type> arr;