Skip to content

Commit 9ec5da3

Browse files
committed
refactor: Move ScheduleBatchPriority to its own file
With the previous move of AlertNotify out of the validation file, and thus out of the kernel library, ScheduleBatchPriority is the last remaining function used by the kernel library from util/system. Move it to its own file, such that util/system can be moved out of the util library in the following few commits. Moving util/system out of the kernel library removes further networking as well as shell related code from it.
1 parent f871c69 commit 9ec5da3

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

src/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ BITCOIN_CORE_H = \
280280
txrequest.h \
281281
undo.h \
282282
util/asmap.h \
283+
util/batchpriority.h \
283284
util/bip32.h \
284285
util/bitdeque.h \
285286
util/bytevectorhash.h \
@@ -711,6 +712,7 @@ libbitcoin_util_a_SOURCES = \
711712
support/cleanse.cpp \
712713
sync.cpp \
713714
util/asmap.cpp \
715+
util/batchpriority.cpp \
714716
util/bip32.cpp \
715717
util/bytevectorhash.cpp \
716718
util/chaintype.cpp \
@@ -963,6 +965,7 @@ libbitcoinkernel_la_SOURCES = \
963965
txdb.cpp \
964966
txmempool.cpp \
965967
uint256.cpp \
968+
util/batchpriority.cpp \
966969
util/chaintype.cpp \
967970
util/check.cpp \
968971
util/exception.cpp \
@@ -978,7 +981,6 @@ libbitcoinkernel_la_SOURCES = \
978981
util/string.cpp \
979982
util/syscall_sandbox.cpp \
980983
util/syserror.cpp \
981-
util/system.cpp \
982984
util/thread.cpp \
983985
util/threadnames.cpp \
984986
util/time.cpp \

src/node/blockstorage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <signet.h>
1818
#include <streams.h>
1919
#include <undo.h>
20+
#include <util/batchpriority.h>
2021
#include <util/fs.h>
2122
#include <util/syscall_sandbox.h>
2223
#include <util/system.h>

src/util/batchpriority.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <logging.h>
6+
#include <util/syserror.h>
7+
8+
#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
9+
#include <pthread.h>
10+
#include <pthread_np.h>
11+
#endif
12+
13+
#ifndef WIN32
14+
#include <sched.h>
15+
#endif
16+
17+
void ScheduleBatchPriority()
18+
{
19+
#ifdef SCHED_BATCH
20+
const static sched_param param{};
21+
const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, &param);
22+
if (rc != 0) {
23+
LogPrintf("Failed to pthread_setschedparam: %s\n", SysErrorString(rc));
24+
}
25+
#endif
26+
}

src/util/batchpriority.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_UTIL_BATCHPRIORITY_H
6+
#define BITCOIN_UTIL_BATCHPRIORITY_H
7+
8+
/**
9+
* On platforms that support it, tell the kernel the calling thread is
10+
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
11+
*
12+
*/
13+
void ScheduleBatchPriority();
14+
15+
#endif // BITCOIN_UTIL_BATCHPRIORITY_H

src/util/system.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77

88
#include <logging.h>
99
#include <util/string.h>
10-
#include <util/syserror.h>
1110
#include <util/time.h>
1211

13-
#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
14-
#include <pthread.h>
15-
#include <pthread_np.h>
16-
#endif
17-
1812
#ifndef WIN32
19-
#include <sched.h>
2013
#include <sys/stat.h>
2114
#else
2215
#include <codecvt>
@@ -112,14 +105,3 @@ int64_t GetStartupTime()
112105
{
113106
return nStartupTime;
114107
}
115-
116-
void ScheduleBatchPriority()
117-
{
118-
#ifdef SCHED_BATCH
119-
const static sched_param param{};
120-
const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, &param);
121-
if (rc != 0) {
122-
LogPrintf("Failed to pthread_setschedparam: %s\n", SysErrorString(rc));
123-
}
124-
#endif
125-
}

src/util/system.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ void runCommand(const std::string& strCommand);
3636
*/
3737
int GetNumCores();
3838

39-
/**
40-
* On platforms that support it, tell the kernel the calling thread is
41-
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
42-
*
43-
*/
44-
void ScheduleBatchPriority();
45-
4639
namespace util {
4740

4841
//! Simplification of std insertion

0 commit comments

Comments
 (0)