File: treiber_stack_hp.cpp

package info (click to toggle)
libcds 2.3.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,632 kB
  • sloc: cpp: 135,002; ansic: 7,234; perl: 243; sh: 237; makefile: 6
file content (148 lines) | stat: -rw-r--r-- 4,015 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) 2006-2018 Maxim Khizhinsky
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

#include "test_treiber_stack.h"

#include <cds/gc/hp.h>
#include <cds/container/treiber_stack.h>

namespace {

    namespace cc = cds::container;
    typedef cds::gc::HP gc_type;

    class TreiberStack_HP : public cds_test::TreiberStack
    {
        typedef cds_test::TreiberStack base_class;

    protected:
        void SetUp()
        {
            typedef cc::TreiberStack< gc_type, int > stack_type;

            cds::gc::hp::GarbageCollector::Construct( stack_type::c_nHazardPtrCount, 1, 16 );
            cds::threading::Manager::attachThread();
        }

        void TearDown()
        {
            cds::threading::Manager::detachThread();
            cds::gc::hp::GarbageCollector::Destruct( true );
        }

        template <typename Stack>
        void test()
        {
            Stack stack;
            base_class::test( stack );
        }

        template <typename Stack>
        void test_dyn( size_t elimination_size )
        {
            Stack stack( elimination_size );
            base_class::test( stack );
        }
    };

    TEST_F( TreiberStack_HP, defaulted )
    {
        typedef cc::TreiberStack< gc_type, int > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, backoff )
    {
        typedef cc::TreiberStack< gc_type, int
            , typename cc::treiber_stack::make_traits<
                cds::opt::back_off< cds::backoff::yield>
            >::type
        > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, alloc )
    {
        // allocator must be rebinded for real value type
        struct foo;

        typedef cc::TreiberStack< gc_type, int
            , typename cc::treiber_stack::make_traits<
                cds::opt::back_off< cds::backoff::pause>
                ,cds::opt::memory_model<cds::opt::v::relaxed_ordering>
                ,cds::opt::allocator< std::allocator< foo >>
            >::type
        > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, elimination )
    {
        typedef cc::TreiberStack< gc_type, int
            , typename cc::treiber_stack::make_traits<
                cds::opt::enable_elimination<true>
            >::type
        > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, elimination_backoff )
    {
        struct traits : public cc::treiber_stack::traits
        {
            enum {
                enable_elimination = true
            };
            typedef cds::backoff::pause back_off;
        };
        typedef cc::TreiberStack< gc_type, int, traits > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, elimination_dynamic )
    {
        typedef cc::TreiberStack< gc_type, int
            , typename cc::treiber_stack::make_traits<
                cds::opt::enable_elimination<true>
                , cds::opt::buffer< cds::opt::v::initialized_dynamic_buffer<void *> >
            >::type
        > stack_type;

        test_dyn<stack_type>( 4 );
    }

    TEST_F( TreiberStack_HP, elimination_stat )
    {
        typedef cc::TreiberStack< gc_type, int
            , typename cc::treiber_stack::make_traits<
                cds::opt::enable_elimination<true>
                , cds::opt::stat< cc::treiber_stack::stat<> >
            >::type
        > stack_type;

        test<stack_type>();
    }

    TEST_F( TreiberStack_HP, elimination_dynamic_backoff )
    {
        struct traits : public cc::treiber_stack::traits
        {
            enum {
                enable_elimination = true
            };
            typedef cds::opt::v::initialized_dynamic_buffer<void *> buffer;
            typedef cds::backoff::yield back_off;
        };
        typedef cc::TreiberStack< gc_type, int, traits > stack_type;

        test_dyn<stack_type>( 2 );
    }

} // namespace