virtual size_t run( void ) { for(;;) { CountPtr< JobQueue::Job > job = q->getJob(); if( size_t(-1) == job->work( q ) ) return 0; Thread::yield(); } }
void test_push_pop_priority( void ) { CountPtr< JobQueue > q = new JobQueue( 0 ); const size_t num_jobs = 16; std::vector< CountPtr< NrJob > > jobs( num_jobs ); for( size_t i=0; i<num_jobs; ++i ) { jobs[ i ] = new NrJob; jobs[ i ]->nr = i; jobs[ i ]->setPriority( i ); CPPUNIT_ASSERT_EQUAL( i, jobs[ i ]->getPriority() ); q->addJob( jobs[ i ].get() ); // std::cerr << "q.addJob( " << (void*)&jobs[ i ] << " ), nr = " << i << std::endl; } for( size_t i=0; i<num_jobs; ++i ) { CountPtr< JobQueue::Job > job = q->getJob(); // std::cerr << "utest_JobQueue: job = " << (void*)job.get() << ", nr = " << job->doit() << std::endl; CPPUNIT_ASSERT_EQUAL( num_jobs-i-1, job->work( q ) ); CPPUNIT_ASSERT_EQUAL( num_jobs-i-1, job->getPriority() ); } }