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.
--- 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