Added copyright and license
[libcds.git] / tests / test-hdr / tree / hdr_bronson_avltree_map_rcu_gpb_pool_monitor.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-2016
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 "tree/hdr_bronson_avltree_map.h"
32 #include <cds/urcu/general_buffered.h>
33 #include <cds/container/bronson_avltree_map_rcu.h>
34 #include <cds/sync/pool_monitor.h>
35 #include <cds/memory/vyukov_queue_pool.h>
36
37 #include "unit/print_bronsonavltree_stat.h"
38 #include "unit/print_sync_monitor_stat.h"
39
40 namespace tree {
41     namespace cc = cds::container;
42     namespace co = cds::opt;
43     namespace {
44         typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_type;
45
46         struct print_stat {
47             template <typename Tree>
48             void operator()( Tree const& t ) const
49             {
50                 std::cout << t.statistics();
51                 std::cout << t.monitor().statistics();
52             }
53         };
54
55         typedef cds::memory::vyukov_queue_pool< std::mutex > simple_pool;
56         typedef cds::memory::lazy_vyukov_queue_pool< std::mutex > lazy_pool;
57         typedef cds::memory::bounded_vyukov_queue_pool< std::mutex > bounded_pool;
58     } // namespace
59
60     void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_less()
61     {
62         struct traits: public
63             cc::bronson_avltree::make_traits<
64                 co::less< std::less<key_type> >
65                 ,co::sync_monitor< cds::sync::pool_monitor<simple_pool> >
66             >::type
67         {};
68         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
69         test<map_type, print_stat>();
70     }
71
72     void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_less_stat()
73     {
74         struct traits: public
75             cc::bronson_avltree::make_traits<
76                 co::less< std::less<key_type> >
77                 ,co::stat< cc::bronson_avltree::stat<> >
78                 ,co::sync_monitor< cds::sync::pool_monitor<lazy_pool, cds::opt::none, true >>
79                 ,cc::bronson_avltree::relaxed_insert< false >
80             >::type
81         {};
82         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
83         test<map_type, print_stat>();
84     }
85
86         void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_cmp_ic_stat()
87     {
88         struct traits: public
89             cc::bronson_avltree::make_traits<
90                 co::compare< compare >
91                 ,co::item_counter< cds::atomicity::item_counter >
92                 ,co::stat< cc::bronson_avltree::stat<> >
93                 ,co::sync_monitor< cds::sync::pool_monitor<bounded_pool, cds::opt::none, true >>
94             >::type
95         {};
96         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
97         test<map_type, print_stat>();
98     }
99
100     void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_cmp_ic_stat_yield()
101     {
102         struct traits: public
103             cc::bronson_avltree::make_traits<
104                 co::compare< compare >
105                 ,co::item_counter< cds::atomicity::item_counter >
106                 ,co::stat< cc::bronson_avltree::stat<> >
107                 ,co::back_off< cds::backoff::yield >
108                 ,co::sync_monitor< cds::sync::pool_monitor<lazy_pool, cds::opt::none, true >>
109             >::type
110         {};
111         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
112         test<map_type, print_stat>();
113     }
114
115     void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_less_relaxed_insert()
116     {
117         struct traits: public
118             cc::bronson_avltree::make_traits<
119                 co::less< std::less<key_type> >
120                 ,cc::bronson_avltree::relaxed_insert< true >
121                 ,co::sync_monitor< cds::sync::pool_monitor<lazy_pool> >
122             >::type
123         {};
124         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
125         test<map_type, print_stat>();
126     }
127
128     void BronsonAVLTreeHdrTest::BronsonAVLTree_rcu_gpb_pool_monitor_less_relaxed_insert_stat()
129     {
130         struct traits: public
131             cc::bronson_avltree::make_traits<
132                 co::less< std::less<key_type> >
133                 ,co::stat< cc::bronson_avltree::stat<> >
134                 ,cc::bronson_avltree::relaxed_insert< true >
135                 ,co::sync_monitor< cds::sync::pool_monitor<simple_pool, cds::opt::none, true >>
136             >::type
137         {};
138         typedef cc::BronsonAVLTreeMap< rcu_type, key_type, value_type, traits > map_type;
139         test<map_type, print_stat>();
140     }
141
142 } // namespace tree