AuroraRuntime/Source/Threading/Sleep.cpp
2021-09-06 11:58:08 +01:00

42 lines
981 B
C++

/***
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_IS_POSIX_DERIVED)
#include <unistd.h>
#endif
namespace Aurora::Threading
{
AUKN_SYM void Sleep(AuUInt64 timeout)
{
#if defined(AURORA_IS_LINUX_DERIVED)
usleep(timeout * 1000000);
#elif defined(AURORA_IS_MODERNNT_DERIVED)
::Sleep(timeout);
#else
std::atomic<bool> value = false;
BooleanWaitable waitable(value);
WaitFor(&waitable, timeout);
#endif
}
AUKN_SYM void SleepNs(AuUInt64 timeout)
{
#if defined(AURORA_IS_LINUX_DERIVED) || defined(AURORA_IS_BSD_DERIVED)
usleep(timeout);
#else
auto status = YieldPollNs(true, timeout + Time::CurrentInternalClockNS(), [=]()
{
return false;
});
#endif
}
}