本文整理汇总了C++中TimePoint::getTimeWaiting方法的典型用法代码示例。如果您正苦于以下问题:C++ TimePoint::getTimeWaiting方法的具体用法?C++ TimePoint::getTimeWaiting怎么用?C++ TimePoint::getTimeWaiting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimePoint
的用法示例。
在下文中一共展示了TimePoint::getTimeWaiting方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkTimeout
bool checkTimeout(
const TimePoint& start,
const TimePoint& end,
nanoseconds expected,
bool allowSmaller,
nanoseconds tolerance) {
auto elapsedTime = end.getTimeStart() - start.getTimeEnd();
if (!allowSmaller) {
// Timeouts should never fire before the time was up.
// Allow 1ms of wiggle room for rounding errors.
if (elapsedTime < (expected - milliseconds(1))) {
return false;
}
}
// Check that the event fired within a reasonable time of the timout.
//
// If the system is under heavy load, our process may have had to wait for a
// while to be run. The time spent waiting for the processor shouldn't
// count against us, so exclude this time from the check.
nanoseconds timeExcluded;
if (end.getTid() != start.getTid()) {
// We can only correctly compute the amount of time waiting to be scheduled
// if both TimePoints were set in the same thread.
timeExcluded = nanoseconds(0);
} else {
timeExcluded = end.getTimeWaiting() - start.getTimeWaiting();
assert(end.getTimeWaiting() >= start.getTimeWaiting());
// Add a tolerance here due to precision issues on linux, see below note.
assert((elapsedTime + tolerance) >= timeExcluded);
}
nanoseconds effectiveElapsedTime(0);
if (elapsedTime > timeExcluded) {
effectiveElapsedTime = elapsedTime - timeExcluded;
}
// On x86 Linux, sleep calls generally have precision only to the nearest
// millisecond. The tolerance parameter lets users allow a few ms of slop.
auto overrun = effectiveElapsedTime - expected;
if (overrun > tolerance) {
return false;
}
return true;
}