AuroraRuntime/Source/Threading/Sleep.cpp
J Reece Wilson d81d4564e9 [+] Initial Linux exit signal handler
[*] Linux Semaphore bug (apparently I can't write loops)
[*] Linux sleep bug
2022-04-07 05:35:17 +01:00

42 lines
992 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 <Source/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 * 1000);
#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 / 1000);
#else
auto status = YieldPollNs(true, timeout + Time::CurrentInternalClockNS(), [=]()
{
return false;
});
#endif
}
}