for ( size_t pass = 0; pass < s_nPassCount; ++pass ) {
item_type* p;
while ( (p = static_cast<item_type*>( m_FreeList.get())) == nullptr );
+ p->counter.fetch_add( 1, atomics::memory_order_relaxed );
m_FreeList.put( p );
}
}
{
cds_test::config const& cfg = get_config( "SequentialFreeList" );
- s_nPassCount = cfg.get_size_t( "SinglePassCount", s_nPassCount );
+ s_nThreadCount = cfg.get_size_t( "ThreadCount", s_nThreadCount );
+ s_nPassCount = cfg.get_size_t( "PassCount", s_nPassCount );
- s_nThreadCount = 1;
+ if ( s_nThreadCount == 0 )
+ s_nThreadCount = 1;
if ( s_nPassCount == 0 )
s_nPassCount = 1000;
}
list.put( &item );
pool.add( new Worker<FreeList>( pool, list ), s_nThreadCount );
- std::unique_ptr<Worker<FreeList>> worker(
- new Worker<FreeList>(pool, list));
- worker->test();
+
+ propout() << std::make_pair( "work_thread", s_nThreadCount )
+ << std::make_pair( "pass_count", s_nPassCount );
+
+ std::chrono::milliseconds duration = pool.run();
+
+ propout() << std::make_pair( "duration", duration );
+
+ // analyze result
+ EXPECT_EQ( item.counter.load( atomics::memory_order_relaxed ), s_nPassCount * s_nThreadCount );
+
list.clear( []( typename FreeList::node* ) {} );
}
};
- size_t put_get_single::s_nThreadCount = 1;
+ size_t put_get_single::s_nThreadCount = 4;
size_t put_get_single::s_nPassCount = 100000;
-#define CDSSTRESS_FREELIST_F(name, freelist_type) \
- TEST_F(put_get_single, name) { \
- std::unique_ptr<freelist_type> fl(new freelist_type()); \
- test(*fl); \
- }
+#define CDSSTRESS_FREELIST_F( name, freelist_type ) \
+ TEST_F( put_get_single, name ) \
+ { \
+ freelist_type fl; \
+ test( fl ); \
+ }
CDSSTRESS_FREELIST_F( FreeList, cds::intrusive::FreeList )
atomics::atomic<tagged_ptr> tp;
if ( tp.is_lock_free()) {
- using FL = cds::intrusive::TaggedFreeList;
- std::unique_ptr<FL> fl(new FL());
- test( *fl );
+ cds::intrusive::TaggedFreeList fl;
+ test( fl );
}
else
std::cout << "Double-width CAS is not supported\n";