Commit 5907fe6e authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

base/allocator: Remove a Lock from PartitionAllocator.

The lock only ensures that initialization is done once. This does not
require a lock, and actually would not require to be done only once at
all since the initialization is idempotent.

This is part of a larger PartitionAlloc refactoring (see linked bug).

Bug: 1061437, 787153
Change-Id: Ie2898b59114216ab76050c47e6d998051d3f3998
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144138Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758198}
parent 58448c74
...@@ -19,6 +19,18 @@ ...@@ -19,6 +19,18 @@
namespace base { namespace base {
namespace {
bool InitializeOnce() {
// We mark the sentinel bucket/page as free to make sure it is skipped by our
// logic to find a new active page.
internal::PartitionBucket::get_sentinel_bucket()->active_pages_head =
internal::PartitionPage::get_sentinel_page();
return true;
}
} // namespace
// Two partition pages are used as guard / metadata page so make sure the super // Two partition pages are used as guard / metadata page so make sure the super
// page size is bigger. // page size is bigger.
static_assert(kPartitionPageSize * 4 <= kSuperPageSize, "ok super page size"); static_assert(kPartitionPageSize * 4 <= kSuperPageSize, "ok super page size");
...@@ -57,12 +69,6 @@ PartitionRootGeneric::PartitionRootGeneric() = default; ...@@ -57,12 +69,6 @@ PartitionRootGeneric::PartitionRootGeneric() = default;
PartitionRootGeneric::~PartitionRootGeneric() = default; PartitionRootGeneric::~PartitionRootGeneric() = default;
PartitionAllocatorGeneric::PartitionAllocatorGeneric() = default; PartitionAllocatorGeneric::PartitionAllocatorGeneric() = default;
Lock& GetLock() {
static NoDestructor<Lock> s_initialized_lock;
return *s_initialized_lock;
}
static bool g_initialized = false;
Lock& GetHooksLock() { Lock& GetHooksLock() {
static NoDestructor<Lock> lock; static NoDestructor<Lock> lock;
return *lock; return *lock;
...@@ -175,21 +181,12 @@ bool PartitionAllocHooks::ReallocOverrideHookIfEnabled(size_t* out, ...@@ -175,21 +181,12 @@ bool PartitionAllocHooks::ReallocOverrideHookIfEnabled(size_t* out,
static void PartitionAllocBaseInit(internal::PartitionRootBase* root) { static void PartitionAllocBaseInit(internal::PartitionRootBase* root) {
DCHECK(!root->initialized); DCHECK(!root->initialized);
{ static bool initialized = InitializeOnce();
AutoLock guard(GetLock()); static_cast<void>(initialized);
if (!g_initialized) {
g_initialized = true;
// We mark the sentinel bucket/page as free to make sure it is skipped by
// our logic to find a new active page.
internal::PartitionBucket::get_sentinel_bucket()->active_pages_head =
internal::PartitionPage::get_sentinel_page();
}
}
root->initialized = true;
// This is a "magic" value so we can test if a root pointer is valid. // This is a "magic" value so we can test if a root pointer is valid.
root->inverted_self = ~reinterpret_cast<uintptr_t>(root); root->inverted_self = ~reinterpret_cast<uintptr_t>(root);
root->initialized = true;
} }
void PartitionAllocGlobalInit(OomFunction on_out_of_memory) { void PartitionAllocGlobalInit(OomFunction on_out_of_memory) {
......
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