AuroraRuntime/Source/Threading/Sleep.cpp

42 lines
988 B
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Sleep.cpp
Date: 2021-6-12
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "Sleep.hpp"
#include "WaitFor.hpp"
#if defined(AURORA_PLATFORM_LINUX)
#include <unistd.h>
#endif
namespace Aurora::Threading
{
AUKN_SYM void Sleep(AuUInt64 timeout)
{
#if defined(AURORA_PLATFORM_LINUX) || defined(AURORA_PLATFORM_ANDROID)
usleep(timeout * 1000000);
#elif defined(AURORA_PLATFORM_WIN32)
::Sleep(timeout);
#else
std::atomic<bool> value = false;
BooleanWaitable waitable(value);
WaitFor(&waitable, timeout);
#endif
}
AUKN_SYM void SleepNs(AuUInt64 timeout)
{
#if defined(AURORA_PLATFORM_LINUX) || defined(AURORA_PLATFORM_ANDROID)
usleep(timeout);
#else
YieldPollNs(true, timeout + Time::CurrentClockNS(), [=]()
{
return false;
});
#endif
}
}