From 0be69025d913810f46518cffde07128167946cc9 Mon Sep 17 00:00:00 2001 From: Jens Stutte Date: Mon, 3 Mar 2025 08:36:55 +0000 Subject: [PATCH] Bug 1949155 - Use Relaxed memory ordering for malloc_initialized. r=glandium We read this flag very often, so we want those reads to be fastest possible. We already protect writes by gInitLock, and on MSVC we even trust it to work without Atomic. So Relaxed should be safe here. Differential Revision: https://phabricator.services.mozilla.com/D238973 --- memory/build/mozjemalloc.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index 975ae60ea692..a1570dbe4901 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -684,7 +684,11 @@ static void* base_alloc(size_t aSize); // threads are created. static bool malloc_initialized; #else -static Atomic malloc_initialized; +// We can rely on Relaxed here because this variable is only ever set when +// holding gInitLock. A thread that still sees it false while another sets it +// true will enter the same lock, synchronize with the former and check the +// flag again under the lock. +static Atomic malloc_initialized; #endif // This lock must be held while bootstrapping us.