text
stringlengths 0
2.2M
|
---|
// class AnotherClock
|
// ==================
|
class AnotherClock {
|
// 'AnotherClock' is a C++11-compatible clock that is very similar to
|
// 'bsl::chrono::steady_clock'. The only difference is that it uses a
|
// different epoch; it begins 10000 "ticks" after the beginning of
|
// 'steady_clock's epoch.
|
private:
|
typedef bsl::chrono::steady_clock base_clock;
|
public:
|
typedef base_clock::duration duration;
|
typedef base_clock::rep rep;
|
typedef base_clock::period period;
|
typedef bsl::chrono::time_point<AnotherClock> time_point;
|
static const bool is_steady = base_clock::is_steady;
|
// CLASS METHODS
|
static time_point now();
|
// Return a time point representing the time since the beginning of the
|
// epoch.
|
};
|
// CLASS METHODS
|
AnotherClock::time_point AnotherClock::now()
|
{
|
base_clock::duration ret = base_clock::now().time_since_epoch();
|
return AnotherClock::time_point(ret - duration(10000));
|
}
|
// ===============
|
// class HalfClock
|
// ===============
|
class HalfClock {
|
// 'HalfClock' is a C++11-compatible clock that is very similar to
|
// 'bsl::chrono::steady_clock'. The difference is that it runs "half as
|
// fast" as 'steady_clock'.
|
private:
|
typedef bsl::chrono::steady_clock base_clock;
|
public:
|
typedef base_clock::duration duration;
|
typedef base_clock::rep rep;
|
typedef base_clock::period period;
|
typedef bsl::chrono::time_point<HalfClock> time_point;
|
static const bool is_steady = base_clock::is_steady;
|
// CLASS METHODS
|
static time_point now();
|
// Return a time point representing the time since the beginning of the
|
// epoch.
|
};
|
// CLASS METHODS
|
HalfClock::time_point HalfClock::now()
|
{
|
base_clock::duration ret = base_clock::now().time_since_epoch();
|
return HalfClock::time_point(ret/2);
|
}
|
// BDE_VERIFY pragma: pop
|
template <class CLOCK>
|
int WaitForTimeout(bslmt::Condition& mX, bslmt::Mutex *m, int secondsToWait)
|
// Wait on the specified 'Condition' 'mX' for the specified 'secondsToWait'
|
// seconds based on the specified 'CLOCK'. If the call to 'timedWait'
|
// (using the specified mutex 'm') returns 'e_TIMED_OUT', indicating that
|
// a timeout has occurred, verify that at least that much time has elapsed
|
// (measured by the clock).
|
{
|
typename CLOCK::time_point tp = CLOCK::now() +
|
bsl::chrono::seconds(secondsToWait);
|
int ret = mX.timedWait(m, tp);
|
if (bslmt::Condition::e_TIMED_OUT == ret) {
|
ASSERT(CLOCK::now() >= tp);
|
}
|
return ret;
|
}
|
#endif
|
// ============================================================================
|
// MAIN PROGRAM
|
// ----------------------------------------------------------------------------
|
int main(int argc, char *argv[])
|
{
|
int test = argc > 1 ? atoi(argv[1]) : 0;
|
verbose = argc > 2;
|
veryVerbose = argc > 3;
|
cout << "TEST " << __FILE__ << " CASE " << test << endl;
|
switch (test) { case 0:
|
case 3: {
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.