Skip to content

Commit 1c066bc

Browse files
committed
Common: updates ffTimeSleep to return true on success
1 parent 2f1e37b commit 1c066bc

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/common/time.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#pragma once
22

3+
#include <stdbool.h>
34
#include <stdint.h>
45
#include <time.h>
56
#ifdef _WIN32
6-
#include <synchapi.h>
7+
#include <ntdef.h>
8+
#include <ntstatus.h>
79
#include <profileapi.h>
810
#include <sysinfoapi.h>
11+
12+
NTSYSCALLAPI
13+
NTSTATUS
14+
NTAPI
15+
NtDelayExecution(
16+
_In_ BOOLEAN Alertable,
17+
_In_ PLARGE_INTEGER DelayInterval);
918
#elif defined(__HAIKU__)
1019
#include <OS.h>
1120
#endif
@@ -49,12 +58,15 @@ static inline uint64_t ffTimeGetNow(void)
4958
#endif
5059
}
5160

52-
static inline void ffTimeSleep(uint32_t msec)
61+
// Returns true if not interrupted
62+
static inline bool ffTimeSleep(uint32_t msec)
5363
{
5464
#ifdef _WIN32
55-
SleepEx(msec, TRUE);
65+
LARGE_INTEGER interval;
66+
interval.QuadPart = -(int64_t) msec * 10000; // Relative time in 100-nanosecond intervals
67+
return NtDelayExecution(TRUE, &interval) == STATUS_SUCCESS;
5668
#else
57-
nanosleep(&(struct timespec){ msec / 1000, (long) (msec % 1000) * 1000000 }, NULL);
69+
return nanosleep(&(struct timespec){ msec / 1000, (long) (msec % 1000) * 1000000 }, NULL) == 0;
5870
#endif
5971
}
6072

src/common/windows/nt.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ NTSYSCALLAPI
237237
NTSTATUS
238238
NTAPI
239239
NtQueryDirectoryFile(
240-
IN HANDLE FileHandle,
241-
IN HANDLE Event OPTIONAL,
242-
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
243-
IN PVOID ApcContext OPTIONAL,
244-
OUT PIO_STATUS_BLOCK IoStatusBlock,
245-
OUT PVOID FileInformation,
246-
IN ULONG Length,
247-
IN FILE_INFORMATION_CLASS FileInformationClass,
248-
IN BOOLEAN ReturnSingleEntry,
249-
IN PUNICODE_STRING FileName OPTIONAL,
250-
IN BOOLEAN RestartScan);
240+
IN HANDLE FileHandle,
241+
IN HANDLE Event OPTIONAL,
242+
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
243+
IN PVOID ApcContext OPTIONAL,
244+
OUT PIO_STATUS_BLOCK IoStatusBlock,
245+
OUT PVOID FileInformation,
246+
IN ULONG Length,
247+
IN FILE_INFORMATION_CLASS FileInformationClass,
248+
IN BOOLEAN ReturnSingleEntry,
249+
IN PUNICODE_STRING FileName OPTIONAL,
250+
IN BOOLEAN RestartScan);

0 commit comments

Comments
 (0)