Commit 1099a5ff authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[platform] Refactor lazily initialized singletons

Use the new macro to define lazily initialized leaky singletons. Avoid
the clumsy LazyInstance, which we can hopefully remove soon.

R=mlippautz@chromium.org

Bug: v8:8600
Change-Id: Ib4d23f275c7ff5ca71fa9b47345284935330ead7
Reviewed-on: https://chromium-review.googlesource.com/c/1397711Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58594}
parent 4eec4449
......@@ -92,8 +92,8 @@ bool g_hard_abort = false;
const char* g_gc_fake_mmap = nullptr;
static LazyInstance<RandomNumberGenerator>::type
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
DEFINE_LAZY_LEAKY_OBJECT_GETTER(RandomNumberGenerator,
GetPlatformRandomNumberGenerator);
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
#if !V8_OS_FUCHSIA
......@@ -188,7 +188,7 @@ size_t OS::CommitPageSize() {
void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) {
MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed);
GetPlatformRandomNumberGenerator()->SetSeed(seed);
}
}
......@@ -197,8 +197,7 @@ void* OS::GetRandomMmapAddr() {
uintptr_t raw_addr;
{
MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->NextBytes(&raw_addr,
sizeof(raw_addr));
GetPlatformRandomNumberGenerator()->NextBytes(&raw_addr, sizeof(raw_addr));
}
#if defined(V8_USE_ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER)
......
......@@ -689,8 +689,8 @@ void OS::StrNCpy(char* dest, int length, const char* src, size_t n) {
#undef _TRUNCATE
#undef STRUNCATE
static LazyInstance<RandomNumberGenerator>::type
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
DEFINE_LAZY_LEAKY_OBJECT_GETTER(RandomNumberGenerator,
GetPlatformRandomNumberGenerator);
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
......@@ -724,7 +724,7 @@ size_t OS::CommitPageSize() {
void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) {
MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed);
GetPlatformRandomNumberGenerator()->SetSeed(seed);
}
}
......@@ -745,8 +745,7 @@ void* OS::GetRandomMmapAddr() {
uintptr_t address;
{
MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->NextBytes(&address,
sizeof(address));
GetPlatformRandomNumberGenerator()->NextBytes(&address, sizeof(address));
}
address <<= kPageSizeBits;
address += kAllocationRandomAddressMin;
......
......@@ -313,21 +313,13 @@ class Clock final {
Mutex mutex_;
};
namespace {
DEFINE_LAZY_LEAKY_OBJECT_GETTER(Clock, GetClock);
};
static LazyStaticInstance<Clock, DefaultConstructTrait<Clock>,
ThreadSafeInitOnceTrait>::type clock =
LAZY_STATIC_INSTANCE_INITIALIZER;
Time Time::Now() {
return clock.Pointer()->Now();
}
Time Time::NowFromSystemTime() {
return clock.Pointer()->NowFromSystemTime();
}
Time Time::Now() { return GetClock()->Now(); }
Time Time::NowFromSystemTime() { return GetClock()->NowFromSystemTime(); }
// Time between windows epoch and standard epoch.
static const int64_t kTimeToEpochInMicroseconds = int64_t{11644473600000000};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment