text
stringlengths
0
2.2M
IMPORTANT_JOBS = 6,
URGENT_JOBS = 4,
OTHER_JOBS = 2
};
int maxProc = static_cast<int>(bsl::max
(1.0, ceil(double(NUM_THREADS) / (NUM_QUEUES-1))-1));
bdlmt::FixedThreadPool tp(NUM_THREADS, MAX_QUEUESIZE, &ta);
TestQueue importantQueue(maxProc, MAX_QUEUESIZE, &tp, &ta);
TestQueue urgentQueue(maxProc, MAX_QUEUESIZE, &tp, &ta);
TestQueue otherQueue(maxProc, MAX_QUEUESIZE, &tp, &ta);
if (0 != tp.start()) {
ASSERT(!"Could not start thread pool! "
"Threads cannot be created!");
break;
}
if (veryVerbose) cout << "Thread-pool Started" << endl;
UsageTestChecker iChecker(importantQueue.multiplexor());
UsageTestChecker uChecker(urgentQueue.multiplexor());
UsageTestChecker oChecker(otherQueue.multiplexor());
for (int i = 0; i < IMPORTANT_JOBS; ++i) {
while(0 != importantQueue.processJob(iChecker));
}
for (int i = 0; i < URGENT_JOBS; ++i) {
while(0 != urgentQueue.processJob(uChecker));
}
for (int i = 0; i < OTHER_JOBS; ++i) {
while(0 != otherQueue.processJob(oChecker));
}
tp.stop();
if (veryVerbose) cout << "Thread-pool Stopped" << endl;
ASSERT(IMPORTANT_JOBS == iChecker.timesCalled());
ASSERT(URGENT_JOBS == uChecker.timesCalled());
ASSERT(OTHER_JOBS == oChecker.timesCalled());
if (veryVerbose) {
P_(IMPORTANT_JOBS); P(iChecker.timesCalled());
P_(URGENT_JOBS); P(uChecker.timesCalled());
P_(OTHER_JOBS); P(oChecker.timesCalled());
}
}
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;
case 2: {
// --------------------------------------------------------------------
// USAGE EXAMPLE TEST
//
// Concerns:
// The usage example provided in the component documentation compiles,
// runs, and behaves as advertised.
//
// Plan:
// Use the 'JobQueue' usage example as the basis for the test.
//
// Testing:
// USAGE EXAMPLE
// --------------------------------------------------------------------
if (verbose) cout << "Usage Example Test" << endl
<< "==================" << endl;
bslma::TestAllocator ta(veryVeryVeryVerbose);
using namespace TEST_CASE_USAGE_EXAMPLE;
usageExample(&ta);
ASSERT(0 < ta.numAllocations());
ASSERT(0 == ta.numBytesInUse());
} break;
case 1: {
// --------------------------------------------------------------------
// BREATHING TEST
//
// Concerns:
// A bdlmt::ThreadMultiplexor object can be constructed and destroyed.
//
// Plan:
// Construct a bdlmt::ThreadMultiplexor object using a test allocator
// and verify that memory is reserved and then returned after
// destruction.
//
// Testing:
// CREATORS
// --------------------------------------------------------------------
if (verbose) cout << "Breathing Test" << endl
<< "==============" << endl;
bslma::TestAllocator ta(veryVeryVeryVerbose);
{