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>
This commit is contained in:
1 parent
30cef53707
commit
93fb0e7897
1 file changed
+7
-4
@@ -8,15 +8,18 @@
|
|||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
Context::Context()
|
Context::Context()
|
||||||
{
|
{
|
||||||
std::string sha256_algo = SHA256AutoDetect();
|
static std::once_flag globals_initialized{};
|
||||||
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
|
std::call_once(globals_initialized, []() {
|
||||||
RandomInit();
|
std::string sha256_algo = SHA256AutoDetect();
|
||||||
|
LogInfo("Using the '%s' SHA256 implementation\n", sha256_algo);
|
||||||
|
RandomInit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user