mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-12 19:20:42 +02:00
utilioprio: Add Windows support as ioprio_set_file_idle
This commit is contained in:
parent
45fa891549
commit
ac2190c22a
25
configure.ac
25
configure.ac
@ -983,6 +983,31 @@ else
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([HAVE_IOPRIO_SYSCALL], [$HAVE_IOPRIO_SYSCALL], [Define to 1 if Linux ioprio syscalls are usable.])
|
||||
|
||||
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"])
|
||||
|
||||
dnl Check for different ways of gathering OS randomness
|
||||
AC_MSG_CHECKING([for Linux getrandom function])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
|
@ -1049,6 +1049,8 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, cons
|
||||
return false;
|
||||
}
|
||||
|
||||
filein.SetIdlePriority();
|
||||
|
||||
// Read block
|
||||
try {
|
||||
filein >> TX_WITH_WITNESS(block);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <util/fs_helpers.h>
|
||||
#include <util/ioprio.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
@ -106,6 +107,11 @@ bool AutoFile::Commit()
|
||||
return ::FileCommit(m_file);
|
||||
}
|
||||
|
||||
void AutoFile::SetIdlePriority()
|
||||
{
|
||||
ioprio_set_file_idle(m_file);
|
||||
}
|
||||
|
||||
bool AutoFile::IsError()
|
||||
{
|
||||
return ferror(m_file);
|
||||
|
@ -455,6 +455,7 @@ public:
|
||||
}
|
||||
|
||||
bool Commit();
|
||||
void SetIdlePriority();
|
||||
bool IsError();
|
||||
bool Truncate(unsigned size);
|
||||
};
|
||||
|
@ -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 @@ public:
|
||||
#define IOPRIO_IDLER(lowprio) (void)lowprio;
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user