text
stringlengths 0
2.2M
|
---|
// The following usage pattern should always be followed:
|
//..
|
// ...
|
bslmt::Condition condition;
|
bslmt::Mutex mutex;
|
mutex.lock();
|
while (false == predicate()) {
|
condition.wait(&mutex);
|
}
|
// Modify shared resources and adjust the predicate here.
|
mutex.unlock();
|
// ...
|
//..
|
// The usage pattern for a timed wait is similar, but has extra branches to
|
// handle a timeout:
|
//..
|
// ...
|
enum { e_TIMED_OUT = -1 };
|
bsls::TimeInterval absTime = bsls::SystemTime::nowRealtimeClock();
|
// Advance 'absTime' to some delta into the future here.
|
mutex.lock();
|
while (false == predicate()) {
|
const int status = condition.timedWait(&mutex, absTime);
|
if (e_TIMED_OUT == status) {
|
break;
|
}
|
}
|
if (false == predicate()) {
|
// The wait timed out and 'predicate' returned 'false'. Perform
|
// timeout logic here.
|
// ...
|
}
|
else {
|
// The condition variable was either signaled or timed out and
|
// 'predicate' returned 'true'. Modify shared resources and adjust
|
// predicate here.
|
// ...
|
}
|
mutex.unlock();
|
// ...
|
//..
|
} break;
|
case 2: {
|
// --------------------------------------------------------------------
|
// TESTING 'clockType'
|
//
|
// Concerns:
|
//: 1 'clockType' returns the clock type passed to the constructor.
|
//:
|
//: 2 'clockType' is declared 'const'.
|
//
|
// Plan:
|
//: 1 Create a 'const' object, and then query it to make sure that the
|
//: correct clock type is returned.
|
//
|
// Testing:
|
// bsls::SystemClockType::Enum clockType() const;
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "TESTING 'clockType'" << endl
|
<< "===================" << endl;
|
const Obj def;
|
ASSERT(bsls::SystemClockType::e_REALTIME == def.clockType());
|
const Obj rt(bsls::SystemClockType::e_REALTIME);
|
ASSERT(bsls::SystemClockType::e_REALTIME == rt.clockType());
|
const Obj mt(bsls::SystemClockType::e_MONOTONIC);
|
ASSERT(bsls::SystemClockType::e_MONOTONIC == mt.clockType());
|
#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
|
const Obj rtC((bsl::chrono::system_clock()));
|
ASSERT(bsls::SystemClockType::e_REALTIME == rtC.clockType());
|
const Obj mtC((bsl::chrono::steady_clock()));
|
ASSERT(bsls::SystemClockType::e_MONOTONIC == mtC.clockType());
|
#endif
|
} break;
|
case 1: {
|
// --------------------------------------------------------------------
|
// TEST THAT THIS IS A CONDITION
|
//
|
// Without relying on anything in, e.g., bslmt_threadutil, test that
|
// this object likely forwards to an appropriate implementation. We'll
|
// test that timedWait on a default-constructed Condition object
|
// returns in roughly the right amount of time. Finally, we'll verify
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.