Skip to content

Commit 052e91f

Browse files
TheCharlatanstickies-v
authored andcommitted
kernel: Only setup kernel context globals once
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. Co-authored-by: stickies-v <stickies-v@protonmail.com>
1 parent c5cbb76 commit 052e91f

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)