Skip to content
Permalink
Browse files

utilioprio: Add Windows support as ioprio_set_file_idle

  • Loading branch information...
luke-jr committed Nov 30, 2016
1 parent 7fb7c77 commit d7c9db1d14b42a0028a97e391ee0fe6ae996bc50
Showing with 56 additions and 0 deletions.
  1. +26 −0 configure.ac
  2. +22 −0 src/util/ioprio.cpp
  3. +6 −0 src/util/ioprio.h
  4. +2 −0 src/validation.cpp
@@ -852,6 +852,31 @@ else
have_ioprio_syscall=no
fi

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)


TEMP_LDFLAGS="$LDFLAGS"
LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
AC_MSG_CHECKING([for thread_local support])
@@ -1457,6 +1482,7 @@ AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
AM_CONDITIONAL([HAVE_IOPOLICY],[test x$have_iopolicy = xyes])
AM_CONDITIONAL([HAVE_IOPRIO_SYSCALL],[test x$have_ioprio_syscall = xyes])
AM_CONDITIONAL([HAVE_WINDOWS_IOPRIO],[test x$have_windows_ioprio = xyes])
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
AM_CONDITIONAL([ENABLE_SSE41],[test x$enable_sse41 = xyes])
@@ -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
@@ -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
@@ -1076,6 +1076,8 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
if (filein.IsNull())
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());

ioprio_set_file_idle(filein.Get());

// Read block
try {
filein >> block;

0 comments on commit d7c9db1

Please sign in to comment.
You can’t perform that action at this time.