Skip to content

Commit

Permalink
utilioprio: Add Windows support as ioprio_set_file_idle
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed May 23, 2022
1 parent e14b8ee commit 65dcf0d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
25 changes: 25 additions & 0 deletions configure.ac
Expand Up @@ -1106,6 +1106,31 @@ else
fi
AM_CONDITIONAL([HAVE_IOPRIO_SYSCALL], [test "$have_ioprio_syscall" = "yes"])

AC_MSG_CHECKING(for Windows file I/O priority functions)
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <io.h>
#include <stdio.h>
]],[[
static const FILE_IO_PRIORITY_HINT_INFO priorityHint = {
.PriorityHint = IoPriorityHintLow,
};
FILE * const F = fopen("test", "r");
HANDLE hFile = _get_osfhandle(_fileno(F));
SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
]])
],[
have_windows_ioprio=yes
AC_DEFINE(HAVE_WINDOWS_IOPRIO,1,[Define this symbol if you have Windows I/O priority functions])
],[
have_windows_ioprio=no
])
AC_MSG_RESULT($have_windows_ioprio)
AM_CONDITIONAL([HAVE_WINDOWS_IOPRIO], [test "$have_windows_ioprio" = "yes"])

if test "$use_thread_local" = "yes" || test "$use_thread_local" = "auto"; then
TEMP_LDFLAGS="$LDFLAGS"
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
Expand Down
2 changes: 2 additions & 0 deletions src/node/blockstorage.cpp
Expand Up @@ -756,6 +756,8 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
}

ioprio_set_file_idle(filein.Get());

// Read block
try {
filein >> block;
Expand Down
22 changes: 22 additions & 0 deletions src/util/ioprio.cpp
Expand Up @@ -55,3 +55,25 @@ int ioprio_set_idle() {
}

#endif


#ifdef HAVE_WINDOWS_IOPRIO

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0600

#include <windows.h>
#include <io.h>

bool ioprio_set_file_idle(FILE * const F) {
static const FILE_IO_PRIORITY_HINT_INFO priorityHint = {
.PriorityHint = IoPriorityHintLow,
};
HANDLE hFile = _get_osfhandle(_fileno(F));

return SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
}

#endif
6 changes: 6 additions & 0 deletions src/util/ioprio.h
Expand Up @@ -54,4 +54,10 @@ class ioprio_idler {
#define IOPRIO_IDLER(actually_idle) (void)actually_idle;
#endif

#ifdef HAVE_WINDOWS_IOPRIO
bool ioprio_set_file_idle(FILE *);
#else
#define ioprio_set_file_idle(f) ((void)false)
#endif

#endif // BITCOIN_UTIL_IOPRIO_H

0 comments on commit 65dcf0d

Please sign in to comment.