mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-12 19:20:42 +02:00
Bugfix: ioprio: Correct type juggling and handle edge cases
This commit is contained in:
parent
0fd00fcb11
commit
8c989494c2
13
configure.ac
13
configure.ac
@ -986,18 +986,23 @@ AC_DEFINE_UNQUOTED([HAVE_IOPRIO_SYSCALL], [$HAVE_IOPRIO_SYSCALL], [Define to 1 i
|
||||
AC_MSG_CHECKING(for Windows file I/O priority functions)
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#define _WIN32_WINNT 0x0601
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
]],[[
|
||||
static const FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
.PriorityHint = IoPriorityHintLow,
|
||||
};
|
||||
FILE * const F = fopen("test", "r");
|
||||
HANDLE hFile = _get_osfhandle(_fileno(F));
|
||||
intptr_t osfhandle = _get_osfhandle(_fileno(F));
|
||||
if (osfhandle == (intptr_t)INVALID_HANDLE_VALUE) osfhandle = 0;
|
||||
HANDLE hFile = (HANDLE)osfhandle;
|
||||
|
||||
SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
|
||||
bool rv = SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
|
||||
return rv;
|
||||
]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
|
@ -59,19 +59,21 @@ int ioprio_set_idle() {
|
||||
|
||||
#if HAVE_WINDOWS_IOPRIO
|
||||
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
#define _WIN32_WINNT 0x0600
|
||||
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
bool ioprio_set_file_idle(FILE * const F) {
|
||||
static const FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
.PriorityHint = IoPriorityHintLow,
|
||||
};
|
||||
HANDLE hFile = _get_osfhandle(_fileno(F));
|
||||
intptr_t osfhandle = _get_osfhandle(_fileno(F));
|
||||
if (osfhandle == (intptr_t)INVALID_HANDLE_VALUE || osfhandle == (intptr_t)-2) {
|
||||
return false;
|
||||
}
|
||||
HANDLE hFile = (HANDLE)osfhandle;
|
||||
|
||||
return SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user