mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-12 19:20:42 +02:00
Merge ionice_win
This commit is contained in:
commit
990ff83c56
30
configure.ac
30
configure.ac
@ -1054,6 +1054,36 @@ 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 0x0601
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
]],[[
|
||||
FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
.PriorityHint = IoPriorityHintLow,
|
||||
};
|
||||
FILE * const F = fopen("test", "r");
|
||||
intptr_t osfhandle = _get_osfhandle(_fileno(F));
|
||||
if (osfhandle == (intptr_t)INVALID_HANDLE_VALUE) osfhandle = 0;
|
||||
HANDLE hFile = (HANDLE)osfhandle;
|
||||
|
||||
bool rv = SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
|
||||
return rv;
|
||||
]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
HAVE_WINDOWS_IOPRIO=1
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
HAVE_WINDOWS_IOPRIO=0
|
||||
])
|
||||
AC_DEFINE_UNQUOTED([HAVE_WINDOWS_IOPRIO], [$HAVE_WINDOWS_IOPRIO], [Define to 1 if Windows file IO functions are usable.])
|
||||
|
||||
dnl Check for different ways of gathering OS randomness
|
||||
AC_MSG_CHECKING([for Linux getrandom function])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
|
@ -1174,6 +1174,8 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, cons
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lowprio) filein.SetIdlePriority();
|
||||
|
||||
// Read block
|
||||
try {
|
||||
filein >> TX_WITH_WITNESS(block);
|
||||
@ -1232,6 +1234,8 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lowprio) filein.SetIdlePriority();
|
||||
|
||||
try {
|
||||
MessageStartChars blk_start;
|
||||
unsigned int blk_size;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <util/fs_helpers.h>
|
||||
#include <util/ioprio.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
@ -107,6 +108,11 @@ bool AutoFile::Commit()
|
||||
return ::FileCommit(m_file);
|
||||
}
|
||||
|
||||
void AutoFile::SetIdlePriority()
|
||||
{
|
||||
ioprio_set_file_idle(m_file);
|
||||
}
|
||||
|
||||
bool AutoFile::IsError()
|
||||
{
|
||||
return ferror(m_file);
|
||||
|
@ -474,6 +474,7 @@ public:
|
||||
}
|
||||
|
||||
bool Commit();
|
||||
void SetIdlePriority();
|
||||
bool IsError();
|
||||
bool Truncate(unsigned size);
|
||||
void AdviseSequential()
|
||||
|
@ -55,3 +55,27 @@ int ioprio_set_idle() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_WINDOWS_IOPRIO
|
||||
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
bool ioprio_set_file_idle(FILE * const F) {
|
||||
FILE_IO_PRIORITY_HINT_INFO priorityHint = {
|
||||
.PriorityHint = IoPriorityHintLow,
|
||||
};
|
||||
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));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -54,4 +54,10 @@ public:
|
||||
#define IOPRIO_IDLER(lowprio) (void)lowprio;
|
||||
#endif
|
||||
|
||||
#if HAVE_WINDOWS_IOPRIO
|
||||
bool ioprio_set_file_idle(FILE *);
|
||||
#else
|
||||
#define ioprio_set_file_idle(f) ((void)false)
|
||||
#endif
|
||||
|
||||
#endif // BITCOIN_UTIL_IOPRIO_H
|
||||
|
@ -5041,6 +5041,7 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||
int nLoaded = 0;
|
||||
try {
|
||||
IOPRIO_IDLER(/*lowprio=*/true);
|
||||
file_in.SetIdlePriority();
|
||||
|
||||
BufferedFile blkdat{file_in, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8};
|
||||
// nRewind indicates where to resume scanning in case something goes wrong,
|
||||
|
Loading…
Reference in New Issue
Block a user