| 293 | } |
| 294 | |
| 295 | bool Duration::sleep() const { |
| 296 | if (Time::useSystemTime()) { |
| 297 | return okvis_wallsleep(sec, nsec); |
| 298 | } else { |
| 299 | Time start = Time::now(); |
| 300 | Time end = start + *this; |
| 301 | if (start.isZero()) { |
| 302 | end = TIME_MAX; |
| 303 | } |
| 304 | |
| 305 | while ((Time::now() < end)) { |
| 306 | okvis_wallsleep(0, 1000000); |
| 307 | |
| 308 | // If we started at time 0 wait for the first actual time to arrive before starting the timer on |
| 309 | // our sleep |
| 310 | if (start.isZero()) { |
| 311 | start = Time::now(); |
| 312 | end = start + *this; |
| 313 | } |
| 314 | |
| 315 | // If time jumped backwards from when we started sleeping, return immediately |
| 316 | if (Time::now() < start) { |
| 317 | return false; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | return true; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | std::ostream& operator<<(std::ostream& os, const WallTime& rhs) { |
| 326 | os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec; |
no test coverage detected