Bug 1412717 - Make malloc_initialized atomic. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 30 Oct 2017 09:30:41 +0900
changeset 688342 75eab9ac72c17970554ab65c9520df1513dc9b12
parent 688341 691d848acd1077cea52b23eb10167fd1b2697ec0
child 688350 8262596b0c94d087528ed3d9280197b254017883
child 688351 04c5907393d7c413ede0ebaf1818a40e27ebe792
push id86720
push userbmo:mh+mozilla@glandium.org
push dateMon, 30 Oct 2017 00:33:10 +0000
reviewersnjn
bugs1412717
milestone58.0a1
Bug 1412717 - Make malloc_initialized atomic. r?njn Interestingly, this turns single-instruction checks into two-instructions checks (at least with GCC, from one cmpb to a movl followed by a testl), but this is due to Atomic<bool> being actually backed by a uint32_t, not by the use of atomics.
memory/build/mozjemalloc.cpp
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -502,17 +502,17 @@ struct MOZ_RAII MutexAutoLock
   ~MutexAutoLock() { mMutex.Unlock(); }
 
 private:
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
   Mutex& mMutex;
 };
 
 // Set to true once the allocator has been initialized.
-static bool malloc_initialized = false;
+static mozilla::Atomic<bool> malloc_initialized(false);
 
 #if defined(XP_WIN)
 // No init lock for Windows.
 #elif defined(XP_DARWIN)
 static Mutex gInitLock = { OS_SPINLOCK_INIT };
 #elif defined(XP_LINUX) && !defined(ANDROID)
 static Mutex gInitLock = { PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP };
 #else