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_segmented_queue.h"
33 #include <cds/gc/hp.h>
34 #include <cds/intrusive/segmented_queue.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::HP gc_type;
41 class IntrusiveSegmentedQueue_HP : public cds_test::intrusive_segmented_queue
43 typedef cds_test::intrusive_segmented_queue base_class;
46 static const size_t c_QuasiFactor = 15;
50 typedef ci::SegmentedQueue< gc_type, item > queue_type;
52 cds::gc::hp::GarbageCollector::Construct( queue_type::c_nHazardPtrCount, 1, 16 );
53 cds::threading::Manager::attachThread();
58 cds::threading::Manager::detachThread();
59 cds::gc::hp::GarbageCollector::Destruct( true );
63 void check_array( V& arr )
65 for ( size_t i = 0; i < arr.size(); ++i ) {
66 EXPECT_EQ( arr[i].nDisposeCount, 2u );
67 EXPECT_EQ( arr[i].nDispose2Count, 1u );
72 TEST_F( IntrusiveSegmentedQueue_HP, defaulted )
74 struct queue_traits : public cds::intrusive::segmented_queue::traits
76 typedef Disposer disposer;
78 typedef cds::intrusive::SegmentedQueue< gc_type, item, queue_traits > queue_type;
80 std::vector<typename queue_type::value_type> arr;
82 queue_type q( c_QuasiFactor );
85 queue_type::gc::force_dispose();
89 TEST_F( IntrusiveSegmentedQueue_HP, mutex )
91 struct queue_traits : public
92 cds::intrusive::segmented_queue::make_traits <
93 cds::intrusive::opt::disposer< Disposer >
94 ,cds::opt::lock_type < std::mutex >
97 typedef cds::intrusive::SegmentedQueue< gc_type, item, queue_traits > queue_type;
99 std::vector<typename queue_type::value_type> arr;
101 queue_type q( c_QuasiFactor );
104 queue_type::gc::force_dispose();
108 TEST_F( IntrusiveSegmentedQueue_HP, shuffle )
110 typedef cds::intrusive::SegmentedQueue< gc_type, item,
111 cds::intrusive::segmented_queue::make_traits<
112 cds::intrusive::opt::disposer< Disposer >
113 ,cds::opt::item_counter< cds::atomicity::item_counter >
114 ,cds::opt::permutation_generator< cds::opt::v::random_shuffle_permutation<> >
118 std::vector<typename queue_type::value_type> arr;
120 queue_type q( c_QuasiFactor );
123 queue_type::gc::force_dispose();
127 TEST_F( IntrusiveSegmentedQueue_HP, padding )
129 struct queue_traits : public cds::intrusive::segmented_queue::traits
131 typedef Disposer disposer;
132 enum { padding = cds::opt::cache_line_padding };
133 typedef ci::segmented_queue::stat<> stat;
135 typedef cds::intrusive::SegmentedQueue< gc_type, item, queue_traits > queue_type;
137 std::vector<typename queue_type::value_type> arr;
139 queue_type q( c_QuasiFactor );
142 queue_type::gc::force_dispose();
146 TEST_F( IntrusiveSegmentedQueue_HP, bigdata_padding )
148 struct queue_traits : public cds::intrusive::segmented_queue::traits
150 typedef Disposer disposer;
151 enum { padding = cds::opt::cache_line_padding | cds::opt::padding_tiny_data_only };
152 typedef cds::opt::v::sequential_consistent memory_model;
154 typedef cds::intrusive::SegmentedQueue< gc_type, big_item, queue_traits > queue_type;
156 std::vector<typename queue_type::value_type> arr;
158 queue_type q( c_QuasiFactor );
161 queue_type::gc::force_dispose();