kernel: Remove batchpriority from kernel library

The current usage of ScheduleBatchPriority is not transparent. Once the
thread scheduling is changed, it remains unchanged for the remainder of
the thread's lifetime. So move the call from `ImportBlocks` to the init
code where it is clearer that its effect lasts for the entire lifetime
of the thread.

Users of the kernel library might not expect `ImportBlocks` to have an
influence on the thread it is called in. Particularly since it is only a
compile time option and cannot be controlled at runtime. With this patch
users of the kernel library can now choose their own scheduling policy.
This commit is contained in:
TheCharlatan 2024-05-10 22:10:34 +02:00
parent 6f1d906438
commit d4b17c7d46
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173
3 changed files with 56 additions and 58 deletions

View file

@ -975,7 +975,6 @@ libbitcoinkernel_la_SOURCES = \
txdb.cpp \
txmempool.cpp \
uint256.cpp \
util/batchpriority.cpp \
util/chaintype.cpp \
util/check.cpp \
util/feefrac.cpp \

View file

@ -69,6 +69,7 @@
#include <txdb.h>
#include <txmempool.h>
#include <util/asmap.h>
#include <util/batchpriority.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
@ -1735,6 +1736,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
chainman.m_thread_load = std::thread(&util::TraceThread, "initload", [=, &chainman, &args, &node] {
ScheduleBatchPriority();
// Import blocks
ImportBlocks(chainman, vImportFiles);
if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {

View file

@ -1175,9 +1175,6 @@ public:
void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFiles)
{
ScheduleBatchPriority();
{
ImportingNow imp{chainman.m_blockman.m_importing};
// -reindex
@ -1237,7 +1234,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
return;
}
}
} // End scope of ImportingNow
// End scope of ImportingNow
}
std::ostream& operator<<(std::ostream& os, const BlockfileType& type) {