diff --git a/time.cpp b/time.cpp index 19638b40..d6867574 100644 --- a/time.cpp +++ b/time.cpp @@ -20,11 +20,12 @@ #include "time.hpp" #include "debug.hpp" +#include "platform.hpp" using namespace util; -#ifdef __WIN32 +#ifdef PLATFORM_WIN32 #include @@ -50,4 +51,21 @@ util::nanoseconds (void) { return static_cast (t.tv_sec) * 1000000000ULL + static_cast (t.tv_nsec); } + + +void +util::sleep (uint64_t ns) { + struct timespec req, rem; + + req.tv_sec = ns / 1000000000UL; + req.tv_nsec = ns % 1000000000UL; + + while (nanosleep (&req, &rem)) { + req = rem; + } +} + #endif + + + diff --git a/time.hpp b/time.hpp index 446c92bf..59fd6eb7 100644 --- a/time.hpp +++ b/time.hpp @@ -24,6 +24,7 @@ namespace util { uint64_t nanoseconds (void); + void sleep (uint64_t ns); } #endif // __UTIL_TIME_HPP