text
stringlengths 0
2.2M
|
---|
// waiting with times in the past returns '-1'.
|
// --------------------------------------------------------------------
|
if (verbose) cout << "Basic forwarding test" << endl
|
<< "=====================" << endl;
|
{
|
Obj x;
|
bslmt::Mutex lock;
|
lock.lock();
|
bsls::Stopwatch timer;
|
timer.start();
|
x.timedWait(&lock, bsls::SystemTime::nowRealtimeClock() + 2);
|
double elapsed = timer.elapsedTime();
|
ASSERT(1.8 <= elapsed && elapsed <= 2.2);
|
lock.unlock();
|
}
|
if (verbose) cout << "Test condition with realtime clock" << endl
|
<< "==================================" << endl;
|
{
|
Obj x(bsls::SystemClockType::e_REALTIME);
|
bslmt::Mutex lock;
|
lock.lock();
|
bsls::Stopwatch timer;
|
timer.start();
|
int rv = x.timedWait(&lock,
|
bsls::SystemTime::nowRealtimeClock() + 2);
|
double elapsed = timer.elapsedTime();
|
ASSERT(Obj::e_TIMED_OUT == rv);
|
ASSERT(1.8 <= elapsed && elapsed <= 2.2);
|
timer.start();
|
rv = x.timedWait(&lock,
|
bsls::SystemTime::nowRealtimeClock() - 1);
|
elapsed = timer.elapsedTime();
|
ASSERT(Obj::e_TIMED_OUT == rv);
|
ASSERT(0.0 <= elapsed && elapsed <= 3.0);
|
lock.unlock();
|
}
|
if (verbose) cout << "Test condition with monotonic clock" << endl
|
<< "===================================" << endl;
|
{
|
Obj x(bsls::SystemClockType::e_MONOTONIC);
|
bslmt::Mutex lock;
|
lock.lock();
|
bsls::Stopwatch timer;
|
timer.start();
|
int rv = x.timedWait(&lock,
|
bsls::SystemTime::nowMonotonicClock() + 2);
|
double elapsed = timer.elapsedTime();
|
ASSERT(Obj::e_TIMED_OUT == rv);
|
ASSERT(1.8 <= elapsed && elapsed <= 2.2);
|
timer.start();
|
rv = x.timedWait(&lock,
|
bsls::SystemTime::nowMonotonicClock() - 1);
|
elapsed = timer.elapsedTime();
|
ASSERT(Obj::e_TIMED_OUT == rv);
|
ASSERT(0.0 <= elapsed && elapsed <= 3.0);
|
lock.unlock();
|
}
|
#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
|
if (verbose) cout << "Test condition with chrono clocks" << endl
|
<< "=================================" << endl;
|
{
|
using namespace bsl::chrono;
|
Obj x;
|
bslmt::Mutex lock;
|
lock.lock();
|
ASSERT(Obj::e_TIMED_OUT ==
|
WaitForTimeout<steady_clock>(x, &lock, 2));
|
ASSERT(Obj::e_TIMED_OUT ==
|
WaitForTimeout<system_clock>(x, &lock, 2));
|
ASSERT(Obj::e_TIMED_OUT ==
|
WaitForTimeout<AnotherClock>(x, &lock, 2));
|
ASSERT(Obj::e_TIMED_OUT ==
|
WaitForTimeout<HalfClock>(x, &lock, 2));
|
lock.unlock();
|
}
|
#endif
|
} break;
|
default: {
|
cerr << "WARNING: CASE `" << test << "' NOT FOUND." << endl;
|
testStatus = -1;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.