mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
This is safe because MilliSleep is never executed in a boost::thread,
the only type of thread that is interruptible.
* The RPC server uses std::thread
* The wallet is either executed in an RPC thread or the main thread
* bitcoin-cli, benchmarks and tests are only one thread (the main thread)
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/MilliSleep\((\S+)\);/UninterruptibleSleep(std::chrono::milliseconds{\1});/g' $(git grep -l MilliSleep)
-END VERIFY SCRIPT-
34 lines
835 B
C++
34 lines
835 B
C++
// Copyright (c) 2015-2019 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <bench/bench.h>
|
|
#include <util/time.h>
|
|
|
|
// Sanity test: this should loop ten times, and
|
|
// min/max/average should be close to 100ms.
|
|
static void Sleep100ms(benchmark::State& state)
|
|
{
|
|
while (state.KeepRunning()) {
|
|
UninterruptibleSleep(std::chrono::milliseconds{100});
|
|
}
|
|
}
|
|
|
|
BENCHMARK(Sleep100ms, 10);
|
|
|
|
// Extremely fast-running benchmark:
|
|
#include <math.h>
|
|
|
|
volatile double sum = 0.0; // volatile, global so not optimized away
|
|
|
|
static void Trig(benchmark::State& state)
|
|
{
|
|
double d = 0.01;
|
|
while (state.KeepRunning()) {
|
|
sum += sin(d);
|
|
d += 0.000001;
|
|
}
|
|
}
|
|
|
|
BENCHMARK(Trig, 12 * 1000 * 1000);
|