Skip to content

Commit d0a6284

Browse files
Merge pull request dashpay#5821 from PastaPastaPasta/develop-trivial-2024-01-13
backport: trivial 2024 01 13
2 parents dfc978a + 2ce8f77 commit d0a6284

File tree

15 files changed

+54
-53
lines changed

15 files changed

+54
-53
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ fi
490490
dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
491491
AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers],[[CXXFLAGS="$CXXFLAGS -fno-extended-identifiers"]],,[[$CXXFLAG_WERROR]])
492492

493+
enable_arm_crc=no
494+
enable_arm_shani=no
493495
enable_sse42=no
494496
enable_sse41=no
495497
enable_avx2=no
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
82bcf405f6db1d55b684a1f63a4aabad376cdad7
1+
577bd51a4b8de066466a445192c1c653872657e2
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
71A3B16735405025D447E8F274810B012346C9A6
22
133EAC179436F14A5CF1B794860FEB804E669320
3-
32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC
43
B8B3F1C0E58C15DB6A81D30C3648A882F4316B9B
5-
CA03882CB1FC067B5D3ACFE4D300116E1C875A3D
64
E777299FC265DD04793070EB944D35F9AC3DB76A
75
D1DBF2C4B96F2DEBF4C16654410108112E7EA81F

doc/build-netbsd.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
NetBSD build guide
1+
NetBSD Build Guide
22
======================
3-
(updated for NetBSD 8.0)
3+
**Updated for NetBSD [8.0](https://www.netbsd.org/releases/formal-8/NetBSD-8.0.html)**
44

55
This guide describes how to build dashd and command-line utilities on NetBSD.
66

src/prevector.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
3737
class prevector {
38+
static_assert(std::is_trivially_copyable_v<T>);
39+
3840
public:
3941
typedef Size size_type;
4042
typedef Diff difference_type;
@@ -428,15 +430,7 @@ class prevector {
428430
// representation (with capacity N and size <= N).
429431
iterator p = first;
430432
char* endp = (char*)&(*end());
431-
if (!std::is_trivially_destructible<T>::value) {
432-
while (p != last) {
433-
(*p).~T();
434-
_size--;
435-
++p;
436-
}
437-
} else {
438-
_size -= last - p;
439-
}
433+
_size -= last - p;
440434
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
441435
return first;
442436
}
@@ -482,9 +476,6 @@ class prevector {
482476
}
483477

484478
~prevector() {
485-
if (!std::is_trivially_destructible<T>::value) {
486-
clear();
487-
}
488479
if (!is_direct()) {
489480
free(_union.indirect_contents.indirect);
490481
_union.indirect_contents.indirect = nullptr;

src/scheduler.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue()
141141
if (m_are_callbacks_running) return;
142142
if (m_callbacks_pending.empty()) return;
143143
}
144-
m_pscheduler->schedule(std::bind(&SingleThreadedSchedulerClient::ProcessQueue, this), std::chrono::system_clock::now());
144+
m_scheduler.schedule([this] { this->ProcessQueue(); }, std::chrono::system_clock::now());
145145
}
146146

147147
void SingleThreadedSchedulerClient::ProcessQueue()
@@ -177,8 +177,6 @@ void SingleThreadedSchedulerClient::ProcessQueue()
177177

178178
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func)
179179
{
180-
assert(m_pscheduler);
181-
182180
{
183181
LOCK(m_callbacks_mutex);
184182
m_callbacks_pending.emplace_back(std::move(func));
@@ -188,7 +186,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func
188186

189187
void SingleThreadedSchedulerClient::EmptyQueue()
190188
{
191-
assert(!m_pscheduler->AreThreadsServicingQueue());
189+
assert(!m_scheduler.AreThreadsServicingQueue());
192190
bool should_continue = true;
193191
while (should_continue) {
194192
ProcessQueue();

src/scheduler.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
#ifndef BITCOIN_SCHEDULER_H
66
#define BITCOIN_SCHEDULER_H
77

8+
#include <attributes.h>
9+
#include <sync.h>
10+
#include <threadsafety.h>
11+
12+
#include <chrono>
813
#include <condition_variable>
14+
#include <cstddef>
915
#include <functional>
1016
#include <list>
1117
#include <map>
1218
#include <thread>
13-
14-
#include <sync.h>
19+
#include <utility>
1520

1621
/**
1722
* Simple class for background tasks that should be run
@@ -117,7 +122,7 @@ class CScheduler
117122
class SingleThreadedSchedulerClient
118123
{
119124
private:
120-
CScheduler* m_pscheduler;
125+
CScheduler& m_scheduler;
121126

122127
Mutex m_callbacks_mutex;
123128
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_callbacks_mutex);
@@ -127,7 +132,7 @@ class SingleThreadedSchedulerClient
127132
void ProcessQueue();
128133

129134
public:
130-
explicit SingleThreadedSchedulerClient(CScheduler* pschedulerIn) : m_pscheduler(pschedulerIn) {}
135+
explicit SingleThreadedSchedulerClient(CScheduler& scheduler LIFETIMEBOUND) : m_scheduler{scheduler} {}
131136

132137
/**
133138
* Add a callback to be executed. Callbacks are executed serially

src/test/scheduler_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
128128
CScheduler scheduler;
129129

130130
// each queue should be well ordered with respect to itself but not other queues
131-
SingleThreadedSchedulerClient queue1(&scheduler);
132-
SingleThreadedSchedulerClient queue2(&scheduler);
131+
SingleThreadedSchedulerClient queue1(scheduler);
132+
SingleThreadedSchedulerClient queue2(scheduler);
133133

134134
// create more threads than queues
135135
// if the queues only permit execution of one task at once then
136136
// the extra threads should effectively be doing nothing
137137
// if they don't we'll get out of order behaviour
138138
std::vector<std::thread> threads;
139139
for (int i = 0; i < 5; ++i) {
140-
threads.emplace_back(std::bind(&CScheduler::serviceQueue, &scheduler));
140+
threads.emplace_back([&] { scheduler.serviceQueue(); });
141141
}
142142

143143
// these are not atomic, if SinglethreadedSchedulerClient prevents

src/validationinterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct MainSignalsInstance {
4545
// our own queue here :(
4646
SingleThreadedSchedulerClient m_schedulerClient;
4747

48-
explicit MainSignalsInstance(CScheduler *pscheduler) : m_schedulerClient(pscheduler) {}
48+
explicit MainSignalsInstance(CScheduler& scheduler LIFETIMEBOUND) : m_schedulerClient(scheduler) {}
4949

5050
void Register(std::shared_ptr<CValidationInterface> callbacks)
5151
{
@@ -97,7 +97,7 @@ static CMainSignals g_signals;
9797
void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler)
9898
{
9999
assert(!m_internals);
100-
m_internals.reset(new MainSignalsInstance(&scheduler));
100+
m_internals = std::make_unique<MainSignalsInstance>(scheduler);
101101
}
102102

103103
void CMainSignals::UnregisterBackgroundSignalScheduler()

src/wallet/wallet.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,8 +1939,10 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
19391939
*/
19401940
CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate)
19411941
{
1942-
int64_t nNow = GetTime();
1943-
int64_t start_time = GetTimeMillis();
1942+
using Clock = std::chrono::steady_clock;
1943+
constexpr auto LOG_INTERVAL{60s};
1944+
auto current_time{Clock::now()};
1945+
auto start_time{Clock::now()};
19441946

19451947
assert(reserver.isReserved());
19461948

@@ -1967,8 +1969,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
19671969
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
19681970
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
19691971
}
1970-
if (GetTime() >= nNow + 60) {
1971-
nNow = GetTime();
1972+
if (Clock::now() >= current_time + LOG_INTERVAL) {
1973+
current_time = Clock::now();
19721974
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
19731975
}
19741976

@@ -2035,7 +2037,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
20352037
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current);
20362038
result.status = ScanResult::USER_ABORT;
20372039
} else {
2038-
WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - start_time);
2040+
auto duration_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time);
2041+
WalletLogPrintf("Rescan completed in %15dms\n", duration_milliseconds.count());
20392042
}
20402043
return result;
20412044
}

0 commit comments

Comments
 (0)