fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / queue / intrusive_vyukov_queue.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #include <cds/intrusive/vyukov_mpmc_cycle_queue.h>
32 #include "test_intrusive_bounded_queue.h"
33
34 namespace {
35
36     class IntrusiveVyukovQueue : public cds_test::intrusive_bounded_queue
37     {
38     public:
39         struct disposer {
40             void operator()( item * p )
41             {
42                 ++p->nDisposeCount;
43             }
44         };
45     };
46
47     static const size_t c_Capacity = 64;
48     static const size_t c_RealCapacity = c_Capacity;
49
50     TEST_F( IntrusiveVyukovQueue, defaulted )
51     {
52         cds::intrusive::VyukovMPMCCycleQueue< item > q( c_Capacity );
53         ASSERT_EQ( q.capacity(), c_RealCapacity );
54         test( q );
55     }
56
57     TEST_F( IntrusiveVyukovQueue, disposer )
58     {
59         struct traits : public cds::intrusive::vyukov_queue::traits
60         {
61             typedef IntrusiveVyukovQueue::disposer disposer;
62             typedef cds::atomicity::item_counter item_counter;
63         };
64
65         cds::intrusive::VyukovMPMCCycleQueue< item, traits > q( c_Capacity );
66         ASSERT_EQ( q.capacity(), c_RealCapacity );
67         test( q );
68     }
69
70     TEST_F( IntrusiveVyukovQueue, static_buffer )
71     {
72         struct traits : public cds::intrusive::vyukov_queue::traits
73         {
74             typedef cds::opt::v::uninitialized_static_buffer< int, c_Capacity > buffer;
75             typedef IntrusiveVyukovQueue::disposer disposer;
76         };
77
78         cds::intrusive::VyukovMPMCCycleQueue< item, traits > q;
79         ASSERT_EQ( q.capacity(), c_RealCapacity );
80         test( q );
81     }
82
83     TEST_F( IntrusiveVyukovQueue, dynamic_buffer )
84     {
85         typedef typename cds::intrusive::vyukov_queue::make_traits<
86             cds::opt::buffer< cds::opt::v::uninitialized_dynamic_buffer< int >>
87             ,cds::opt::item_counter< cds::atomicity::item_counter >
88             ,cds::opt::back_off< cds::backoff::pause >
89             ,cds::intrusive::opt::disposer< disposer >
90         >::type traits;
91
92         cds::intrusive::VyukovMPMCCycleQueue< item, traits > q( c_Capacity );
93         ASSERT_EQ( q.capacity(), c_RealCapacity );
94         test( q );
95     }
96
97     TEST_F( IntrusiveVyukovQueue, padding )
98     {
99         struct traits : public cds::intrusive::vyukov_queue::traits
100         {
101             typedef cds::opt::v::uninitialized_static_buffer< int, c_Capacity > buffer;
102             typedef IntrusiveVyukovQueue::disposer disposer;
103             enum { padding = 16 | cds::opt::padding_tiny_data_only };
104         };
105
106         cds::intrusive::VyukovMPMCCycleQueue< item, traits > q;
107         ASSERT_EQ( q.capacity(), c_RealCapacity );
108         test( q );
109     }
110
111
112 } // namespace