Skip to content

Commit c6b4718

Browse files
committed
Merge bitcoin/bitcoin#30537: kernel: Only setup kernel context globals once
93fb0e7 kernel: Only setup kernel context globals once (TheCharlatan) Pull request description: The globals setup by the function calls when creating a new kernel context only need to be setup once. Calling them multiple times may be wasteful and has no apparent benefit. Besides kernel users potentially creating multiple contexts, this change may also be useful for tests creating multiple setups. ACKs for top commit: stickies-v: re-ACK 93fb0e7 maflcko: ACK 93fb0e7 👝 tdb3: re ACK 93fb0e7 Tree-SHA512: c8418c23b34883b9b6af2b93c48760a931c246c9190fae372fb808f573408d332f53ca43b9c783eef561c4a6681e2fb63f215c939b40a87d597c0518dabea22a
2 parents 33884e7 + 93fb0e7 commit c6b4718

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/kernel/context.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
#include <logging.h>
99
#include <random.h>
1010

11+
#include <mutex>
1112
#include <string>
1213

13-
1414
namespace kernel {
1515
Context::Context()
1616
{
17-
std::string sha256_algo = SHA256AutoDetect();
18-
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
19-
RandomInit();
17+
static std::once_flag globals_initialized{};
18+
std::call_once(globals_initialized, []() {
19+
std::string sha256_algo = SHA256AutoDetect();
20+
LogInfo("Using the '%s' SHA256 implementation\n", sha256_algo);
21+
RandomInit();
22+
});
2023
}
2124

2225

0 commit comments

Comments
 (0)