diff --git a/src/common/time.h b/src/common/time.h index 867980f12..de32bb843 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -1,11 +1,20 @@ #pragma once +#include #include #include #ifdef _WIN32 - #include + #include + #include #include #include + + NTSYSCALLAPI + NTSTATUS + NTAPI + NtDelayExecution( + _In_ BOOLEAN Alertable, + _In_ PLARGE_INTEGER DelayInterval); #elif defined(__HAIKU__) #include #endif @@ -49,12 +58,15 @@ static inline uint64_t ffTimeGetNow(void) #endif } -static inline void ffTimeSleep(uint32_t msec) +// Returns true if not interrupted +static inline bool ffTimeSleep(uint32_t msec) { #ifdef _WIN32 - SleepEx(msec, TRUE); + LARGE_INTEGER interval; + interval.QuadPart = -(int64_t) msec * 10000; // Relative time in 100-nanosecond intervals + return NtDelayExecution(TRUE, &interval) == STATUS_SUCCESS; #else - nanosleep(&(struct timespec){ msec / 1000, (long) (msec % 1000) * 1000000 }, NULL); + return nanosleep(&(struct timespec){ msec / 1000, (long) (msec % 1000) * 1000000 }, NULL) == 0; #endif } diff --git a/src/common/windows/nt.h b/src/common/windows/nt.h index 8d6af4b7e..2110836ab 100644 --- a/src/common/windows/nt.h +++ b/src/common/windows/nt.h @@ -237,14 +237,14 @@ NTSYSCALLAPI NTSTATUS NTAPI NtQueryDirectoryFile( - IN HANDLE FileHandle, - IN HANDLE Event OPTIONAL, - IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, - IN PVOID ApcContext OPTIONAL, - OUT PIO_STATUS_BLOCK IoStatusBlock, - OUT PVOID FileInformation, - IN ULONG Length, - IN FILE_INFORMATION_CLASS FileInformationClass, - IN BOOLEAN ReturnSingleEntry, - IN PUNICODE_STRING FileName OPTIONAL, - IN BOOLEAN RestartScan); + IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID FileInformation, + IN ULONG Length, + IN FILE_INFORMATION_CLASS FileInformationClass, + IN BOOLEAN ReturnSingleEntry, + IN PUNICODE_STRING FileName OPTIONAL, + IN BOOLEAN RestartScan);