2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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/dhp.h>
34 #include <cds/intrusive/optimistic_queue.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::DHP gc_type;
42 class IntrusiveOptQueue_DHP : public cds_test::intrusive_msqueue
44 typedef cds_test::intrusive_msqueue base_class;
47 typedef typename base_class::base_hook_item< ci::optimistic_queue::node<gc_type>> base_item_type;
48 typedef typename base_class::member_hook_item< ci::optimistic_queue::node<gc_type>> member_item_type;
52 typedef ci::OptimisticQueue< gc_type, base_item_type,
53 typename ci::optimistic_queue::make_traits<
54 ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc<gc_type>>>
58 cds::gc::dhp::smr::construct( queue_type::c_nHazardPtrCount );
59 cds::threading::Manager::attachThread();
64 cds::threading::Manager::detachThread();
65 cds::gc::dhp::smr::destruct();
69 void check_array( V& arr )
71 for ( size_t i = 0; i < arr.size() - 1; ++i ) {
72 ASSERT_EQ( arr[i].nDisposeCount, 2 );
74 ASSERT_EQ( arr.back().nDisposeCount, 1 );
78 TEST_F( IntrusiveOptQueue_DHP, base_hook )
80 typedef cds::intrusive::OptimisticQueue< gc_type, base_item_type,
81 typename ci::optimistic_queue::make_traits<
82 ci::opt::disposer< mock_disposer >
83 ,ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc<gc_type>>>
87 std::vector<base_item_type> arr;
97 TEST_F( IntrusiveOptQueue_DHP, base_item_counting )
99 typedef cds::intrusive::OptimisticQueue< gc_type, base_item_type,
100 typename ci::optimistic_queue::make_traits<
101 ci::opt::disposer< mock_disposer >
102 , cds::opt::item_counter< cds::atomicity::item_counter >
103 , ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc<gc_type>>>
107 std::vector<base_item_type> arr;
117 TEST_F( IntrusiveOptQueue_DHP, base_stat )
119 struct traits : public ci::optimistic_queue::traits
121 typedef ci::optimistic_queue::base_hook< ci::opt::gc<gc_type>> hook;
122 typedef mock_disposer disposer;
123 typedef cds::atomicity::item_counter item_counter;
124 typedef ci::optimistic_queue::stat<> stat;
125 typedef cds::opt::v::sequential_consistent memory_model;
127 typedef cds::intrusive::OptimisticQueue< gc_type, base_item_type, traits > test_queue;
129 std::vector<base_item_type> arr;
139 TEST_F( IntrusiveOptQueue_DHP, member_hook )
141 typedef cds::intrusive::OptimisticQueue< gc_type, member_item_type,
142 typename ci::optimistic_queue::make_traits<
143 ci::opt::disposer< mock_disposer >
144 ,ci::opt::hook< ci::optimistic_queue::member_hook<
145 offsetof( member_item_type, hMember ),
151 std::vector<member_item_type> arr;
161 TEST_F( IntrusiveOptQueue_DHP, member_hook_stat )
163 struct traits : public ci::optimistic_queue::traits
165 typedef ci::optimistic_queue::member_hook<
166 offsetof( member_item_type, hMember ),
169 typedef mock_disposer disposer;
170 typedef cds::atomicity::item_counter item_counter;
171 typedef ci::optimistic_queue::stat<> stat;
172 typedef cds::opt::v::sequential_consistent memory_model;
174 typedef cds::intrusive::OptimisticQueue< gc_type, member_item_type, traits > test_queue;
176 std::vector<member_item_type> arr;