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 );
}
}
list.put( &item );
pool.add( new Worker<FreeList>( pool, list ), s_nThreadCount );
-
- 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 );
-
+ std::unique_ptr<Worker<FreeList>> worker(
+ new Worker<FreeList>(pool, list));
+ worker->test();
list.clear( []( typename FreeList::node* ) {} );
}
};
size_t put_get_single::s_nThreadCount = 1;
size_t put_get_single::s_nPassCount = 100000;
-#define CDSSTRESS_FREELIST_F( name, freelist_type ) \
- TEST_F( put_get_single, name ) \
- { \
- freelist_type fl; \
- test( fl ); \
- }
+#define CDSSTRESS_FREELIST_F(name, freelist_type) \
+ TEST_F(put_get_single, name) { \
+ std::unique_ptr<freelist_type> fl(new freelist_type()); \
+ test(*fl); \
+ }
CDSSTRESS_FREELIST_F( FreeList, cds::intrusive::FreeList )
atomics::atomic<tagged_ptr> tp;
if ( tp.is_lock_free()) {
- cds::intrusive::TaggedFreeList fl;
- test( fl );
+ using FL = cds::intrusive::TaggedFreeList;
+ std::unique_ptr<FL> fl(new FL());
+ test( *fl );
}
else
std::cout << "Double-width CAS is not supported\n";