1
0
Fork 0

source/Platform/Unix: stub implementation

This commit is contained in:
Henrik Hautakoski 2019-06-01 01:13:44 +02:00
parent 4d69ff3a18
commit 6464838159
20 changed files with 498 additions and 2 deletions

View file

@ -0,0 +1,31 @@
#include <errno.h>
#include <time.h>
#include <Spectre/System/System.h>
namespace sp {
unsigned long system::getMilliseconds()
{
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return (tv.tv_sec * 1000ul) + (tv.tv_nsec / 1000000ul);
}
void system::sleep(int milliseconds)
{
struct timespec req, rem;
req.tv_sec = milliseconds / 1000ul;
req.tv_nsec = (milliseconds - (req.tv_sec * 1000ul)) * 1000000ul;
_start:
// Try again if we get interrupted.
if (clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem) == EINTR) {
// Update req with remaining time.
req = rem;
goto _start;
}
}
} // namespace sp