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 <cds_test/stress_test.h>
33 #include <cds/intrusive/free_list.h>
34 #include <cds/intrusive/free_list_cached.h>
35 #ifdef CDS_DCAS_SUPPORT
36 # include <cds/intrusive/free_list_tagged.h>
40 class put_get_single: public cds_test::stress_fixture
43 static size_t s_nThreadCount;
44 static size_t s_nPassCount;
46 template <typename FreeList >
47 struct value_type: public FreeList::node
49 atomics::atomic<size_t> counter;
56 template <class FreeList>
57 class Worker: public cds_test::thread
59 typedef cds_test::thread base_class;
62 size_t m_nSuccess = 0;
65 Worker( cds_test::thread_pool& pool, FreeList& s )
72 , m_FreeList( src.m_FreeList )
75 virtual thread * clone()
77 return new Worker( *this );
82 typedef value_type<FreeList> item_type;
84 for ( size_t pass = 0; pass < s_nPassCount; ++pass ) {
86 while ( (p = static_cast<item_type*>( m_FreeList.get())) == nullptr );
93 static void SetUpTestCase()
95 cds_test::config const& cfg = get_config( "SequentialFreeList" );
97 s_nPassCount = cfg.get_size_t( "SinglePassCount", s_nPassCount );
100 if ( s_nPassCount == 0 )
103 //static void TearDownTestCase();
107 template <typename FreeList>
108 void test( FreeList& list )
110 cds_test::thread_pool& pool = get_pool();
112 value_type<FreeList> item;;
115 pool.add( new Worker<FreeList>( pool, list ), s_nThreadCount );
116 std::unique_ptr<Worker<FreeList>> worker(
117 new Worker<FreeList>(pool, list));
119 list.clear( []( typename FreeList::node* ) {} );
123 size_t put_get_single::s_nThreadCount = 1;
124 size_t put_get_single::s_nPassCount = 100000;
126 #define CDSSTRESS_FREELIST_F(name, freelist_type) \
127 TEST_F(put_get_single, name) { \
128 std::unique_ptr<freelist_type> fl(new freelist_type()); \
132 CDSSTRESS_FREELIST_F( FreeList, cds::intrusive::FreeList )
134 typedef cds::intrusive::CachedFreeList<cds::intrusive::FreeList> cached_free_list;
135 CDSSTRESS_FREELIST_F( CachedFreeList, cached_free_list )
137 #ifdef CDS_DCAS_SUPPORT
138 TEST_F( put_get_single, TaggetFreeList )
145 atomics::atomic<tagged_ptr> tp;
146 if ( tp.is_lock_free()) {
147 using FL = cds::intrusive::TaggedFreeList;
148 std::unique_ptr<FL> fl(new FL());
152 std::cout << "Double-width CAS is not supported\n";