2015-07-23 14:13:09 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-07-23 14:13:09 +10:00
|
|
|
*
|
2016-04-05 11:02:54 +10:00
|
|
|
* Copyright 2010-2016 Danny Robson <danny@nerdcruft.net>
|
2015-07-23 14:13:09 +10:00
|
|
|
*/
|
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "time.hpp"
|
2015-07-23 14:13:09 +10:00
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "cast.hpp"
|
2015-07-23 14:13:09 +10:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
|
2016-04-05 11:02:54 +10:00
|
|
|
static constexpr uint64_t SECOND = 1'000'000'000UL;
|
2015-07-23 14:13:09 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
util::sleep (uint64_t ns)
|
|
|
|
{
|
|
|
|
struct timespec req, rem;
|
|
|
|
|
2018-01-16 15:11:15 +11:00
|
|
|
req.tv_sec = util::cast::lossless<time_t> (ns / SECOND);
|
|
|
|
req.tv_nsec = util::cast::lossless<long > (ns % SECOND);
|
2015-07-23 14:13:09 +10:00
|
|
|
|
|
|
|
while (nanosleep (&req, &rem)) {
|
|
|
|
req = rem;
|
|
|
|
}
|
|
|
|
}
|