}
using namespace ns_BoundedQueue_Fullness;
+ class VyukovMPMCCycleQueue_dyn_fair_ : public Types<size_t>::VyukovMPMCCycleQueue_dyn_ic
+ {
+ typedef Types<size_t>::VyukovMPMCCycleQueue_dyn_ic base_class;
+ public:
+ typedef base_class::value_type value_type;
+
+ VyukovMPMCCycleQueue_dyn_fair_()
+ : base_class()
+ {}
+
+ VyukovMPMCCycleQueue_dyn_fair_( size_t nCapacity )
+ : base_class( nCapacity )
+ {}
+
+ bool enqueue( value_type const& data )
+ {
+ bool ret;
+ do {
+ ret = base_class::enqueue( data );
+ } while ( !ret && size() != capacity() );
+ return ret;
+ }
+
+ bool push( value_type const& data )
+ {
+ return enqueue( data );
+ }
+
+ bool dequeue( value_type& dest )
+ {
+ bool ret;
+ do {
+ ret = base_class::dequeue( dest );
+ } while ( !ret && size() != capacity() );
+ return ret;
+ }
+
+ bool pop( value_type& dest )
+ {
+ return dequeue( dest );
+ }
+
+ size_t size() const { return base_class::size(); }
+ size_t capacity() const { return base_class::capacity(); }
+ };
+
class BoundedQueue_Fullness: public CppUnitMini::TestCase
{
template <class Queue>
template <class Queue>
void test()
{
- Queue testQueue;
+ Queue testQueue( s_nQueueSize );
CppUnitMini::ThreadPool pool( *this );
pool.add( new Thread<Queue>( pool, testQueue ), s_nThreadCount );
for ( size_t i = 0; i < nSize; ++i )
testQueue.push( i );
- CPPUNIT_MSG( " Thread count=" << s_nThreadCount << " ...");
- pool.run();
-
- analyze( pool, testQueue );
-
- CPPUNIT_MSG( testQueue.statistics() );
- }
-
- template <class Queue>
- void test_bounded()
- {
- size_t nStart = 0;
- size_t nThreadItemCount = s_nQueueSize / s_nThreadCount;
-
- Queue testQueue( s_nQueueSize );
-
- CppUnitMini::ThreadPool pool( *this );
- pool.add( new Thread<Queue>( pool, testQueue ), s_nThreadCount );
-
- for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
- Thread<Queue> * pThread = reinterpret_cast<Thread<Queue> *>(*it);
- pThread->m_nStartItem = nStart;
- nStart += nThreadItemCount;
- pThread->m_nEndItem = nStart;
- }
-
- CPPUNIT_MSG( " Push test, thread count=" << s_nThreadCount << " ...");
+ CPPUNIT_MSG( " Thread count=" << s_nThreadCount << ", push/pop pairs=" << s_nPassCount
+ << ", queue capacity=" << testQueue.capacity() << " ...");
pool.run();
analyze( pool, testQueue );
CPPUNIT_MSG( testQueue.statistics() );
}
-
- template <class Queue>
- void test_segmented()
- {
- CPPUNIT_MSG( " Push test, thread count=" << s_nThreadCount << " ...");
- for ( size_t nSegmentSize = 4; nSegmentSize <= 256; nSegmentSize *= 4 ) {
- CPPUNIT_MSG( "Segment size: " << nSegmentSize );
-
- Queue testQueue( nSegmentSize );
-
- CppUnitMini::ThreadPool pool( *this );
- pool.add( new Thread<Queue>( pool, testQueue ), s_nThreadCount );
-
- size_t nStart = 0;
- size_t nThreadItemCount = s_nQueueSize / s_nThreadCount;
- for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it ) {
- Thread<Queue> * pThread = reinterpret_cast<Thread<Queue> *>(*it);
- pThread->m_nStartItem = nStart;
- nStart += nThreadItemCount;
- pThread->m_nEndItem = nStart;
- }
-
- pool.run();
-
- analyze( pool, testQueue );
-
- CPPUNIT_MSG( testQueue.statistics() );
- }
- }
-
void setUpParams( const CppUnitMini::TestCfg& cfg ) {
s_nThreadCount = cfg.getULong("ThreadCount", 8 );
s_nQueueSize = cfg.getULong("QueueSize", 1024 );
protected:
CDSUNIT_DECLARE_TsigasCycleQueue( size_t )
CDSUNIT_DECLARE_VyukovMPMCCycleQueue( size_t )
+ void VyukovMPMCCycleQueue_dyn_fair()
+ {
+ test< VyukovMPMCCycleQueue_dyn_fair_ >();
+ }
CPPUNIT_TEST_SUITE( BoundedQueue_Fullness )
CDSUNIT_TEST_TsigasCycleQueue
CDSUNIT_TEST_VyukovMPMCCycleQueue
+ CPPUNIT_TEST( VyukovMPMCCycleQueue_dyn_fair_ ) \
CPPUNIT_TEST_SUITE_END();
};