include/llfio/v2.0/detail/impl/windows/import.hpp
// Sleep the thread until some deadline
Sleep the thread until some deadline
Sleep the thread until some deadline
inline bool ntsleep(const deadline &d, bool return_on_alert = false) noexcept
{
  windows_nt_kernel::init();
  using namespace windows_nt_kernel;
  LLFIO_WIN_DEADLINE_TO_SLEEP_INIT(d);
  alignas(8) LARGE_INTEGER infinity{};
  infinity.QuadPart = INT64_MIN;
  for(;;)
  {
    LLFIO_WIN_DEADLINE_TO_SLEEP_LOOP(d);
    NTSTATUS ntstat = NtDelayExecution(1u, timeout != nullptr ? timeout : &infinity);
    (void) ntstat;
    if((d).steady)
    {
      if(std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs)))
      {
        return false;
      }
    }
    else
    {
      if(std::chrono::system_clock::now() >= end_utc)
      {
        return false;
      }
    }
    if(return_on_alert)
    {
      return true;
    }
  }
}
inline bool ntsleep ( const deadline & d , bool return_on_alert = false ) noexcept { windows_nt_kernel :: init ( ) ; using namespace windows_nt_kernel ; LLFIO_WIN_DEADLINE_TO_SLEEP_INIT ( d ) ; alignas ( 8 ) LARGE_INTEGER infinity { } ; infinity . QuadPart = INT64_MIN ; for ( ; ; ) { LLFIO_WIN_DEADLINE_TO_SLEEP_LOOP ( d ) ; NTSTATUS ntstat = NtDelayExecution ( 1u , timeout != nullptr ? timeout : & infinity ) ; ( void ) ntstat ; if ( ( d ) . steady ) { if ( std :: chrono :: steady_clock :: now ( ) >= ( began_steady + std :: chrono :: nanoseconds ( ( d ) . nsecs ) ) ) { return false ; } } else { if ( std :: chrono :: system_clock :: now ( ) >= end_utc ) { return false ; } } if ( return_on_alert ) { return true ; } } }
Sleep the thread until some deadline
Sleep the thread until some deadline
// Pump alerts and APCs