| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- // 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_set_hp.h"
- #include <cds/container/michael_list_hp.h>
- #include <cds/container/michael_set.h>
- namespace {
- namespace cc = cds::container;
- typedef cds::gc::HP gc_type;
- class MichaelSet_HP : public cds_test::container_set_hp
- {
- protected:
- typedef cds_test::container_set_hp base_class;
- void SetUp()
- {
- typedef cc::MichaelList< gc_type, int_item > list_type;
- typedef cc::MichaelHashSet< gc_type, list_type > set_type;
- // +1 - for guarded_ptr
- cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
- cds::threading::Manager::attachThread();
- }
- void TearDown()
- {
- cds::threading::Manager::detachThread();
- cds::gc::hp::GarbageCollector::Destruct( true );
- }
- };
- TEST_F( MichaelSet_HP, compare )
- {
- typedef cc::MichaelList< gc_type, int_item,
- typename cc::michael_list::make_traits<
- cds::opt::compare< cmp >
- >::type
- > list_type;
- typedef cc::MichaelHashSet< gc_type, list_type,
- typename cc::michael_set::make_traits<
- cds::opt::hash< hash_int >
- >::type
- > set_type;
- set_type s( kSize, 2 );
- test( s );
- }
- TEST_F( MichaelSet_HP, less )
- {
- typedef cc::MichaelList< gc_type, int_item,
- typename cc::michael_list::make_traits<
- cds::opt::less< base_class::less >
- >::type
- > list_type;
- typedef cc::MichaelHashSet< gc_type, list_type,
- typename cc::michael_set::make_traits<
- cds::opt::hash< hash_int >
- >::type
- > set_type;
- set_type s( kSize, 2 );
- test( s );
- }
- TEST_F( MichaelSet_HP, cmpmix )
- {
- struct list_traits : public cc::michael_list::traits
- {
- typedef base_class::less less;
- typedef cmp compare;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- typedef cc::MichaelHashSet< gc_type, list_type,
- typename cc::michael_set::make_traits<
- cds::opt::hash< hash_int >
- >::type
- > set_type;
- set_type s( kSize, 2 );
- test( s );
- }
- TEST_F( MichaelSet_HP, item_counting )
- {
- struct list_traits : public cc::michael_list::traits
- {
- typedef cmp compare;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- struct set_traits: public cc::michael_set::traits
- {
- typedef hash_int hash;
- typedef simple_item_counter item_counter;
- };
- typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
- set_type s( kSize, 3 );
- test( s );
- }
- TEST_F( MichaelSet_HP, backoff )
- {
- struct list_traits : public cc::michael_list::traits
- {
- typedef cmp compare;
- typedef cds::backoff::make_exponential_t<cds::backoff::pause, cds::backoff::yield> back_off;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- struct set_traits : public cc::michael_set::traits
- {
- typedef hash_int hash;
- typedef cds::atomicity::item_counter item_counter;
- };
- typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
- set_type s( kSize, 4 );
- test( s );
- }
- TEST_F( MichaelSet_HP, seq_cst )
- {
- struct list_traits : public cc::michael_list::traits
- {
- typedef base_class::less less;
- typedef cds::backoff::pause back_off;
- typedef cds::opt::v::sequential_consistent memory_model;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- struct set_traits : public cc::michael_set::traits
- {
- typedef hash_int hash;
- typedef cds::atomicity::item_counter item_counter;
- };
- typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
- set_type s( kSize, 4 );
- test( s );
- }
- TEST_F( MichaelSet_HP, stat )
- {
- struct list_traits: public cc::michael_list::traits
- {
- typedef base_class::less less;
- typedef cds::backoff::pause back_off;
- typedef cc::michael_list::stat<> stat;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- struct set_traits: public cc::michael_set::traits
- {
- typedef hash_int hash;
- typedef cds::atomicity::item_counter item_counter;
- };
- typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
- set_type s( kSize, 4 );
- test( s );
- EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
- }
- TEST_F( MichaelSet_HP, wrapped_stat )
- {
- struct list_traits: public cc::michael_list::traits
- {
- typedef base_class::less less;
- typedef cds::backoff::pause back_off;
- typedef cc::michael_list::wrapped_stat<> stat;
- };
- typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
- struct set_traits: public cc::michael_set::traits
- {
- typedef hash_int hash;
- typedef cds::atomicity::item_counter item_counter;
- };
- typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
- set_type s( kSize, 4 );
- test( s );
- EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
- }
- } // namespace
|