AuroraRuntime/Source/IO/Loop/LSFromFdNonblocking.hpp

43 lines
1.2 KiB
C++
Raw Normal View History

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSFromFdNonblocking.cpp
2022-04-05 05:59:23 +00:00
Date: 2022-4-5
Author: Reece
***/
#pragma once
#if defined(AURORA_IS_LINUX_DERIVED)
namespace Aurora::IO::UNIX
{
bool LinuxOverlappedYield(bool bUserspaceOnly);
}
#endif
namespace Aurora::IO::Loop
{
template<typename T>
inline bool IsSignaledFromNonblockingImpl(ILoopSourceEx *source, T * that, bool(T::*IsSignaledNonblocking)(), bool bIOTick)
{
bool val {};
source->OnPresleep();
val = ((that)->*(IsSignaledNonblocking))();
source->OnFinishSleep();
// Required for precise Windows on Linux OVERLAPPED semantics for emulators.
// IAsyncTransaction::Complete()/Wait() will always enter an alertable state and dispatch io completion callbacks.
// In theory, we don't need this.
// In practice, if NT can atomically set an event and update the apc queue, we could be out of parity.
if (bIOTick)
{
#if defined(AURORA_IS_LINUX_DERIVED)
// Do not syscall after read or select again under Linux
UNIX::LinuxOverlappedYield(true);
#else
IOYield();
#endif
}
return val;
}
}