From 316b5113e0dab0bfc8b125926372136789a81d40 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Thu, 28 Jan 2021 11:05:02 +0000 Subject: [PATCH] Bug 1633239 - make the bitfields on CacheStorageService atomic. r=valentin,necko-reviewers this is only a hypothetical fix to the underlying issue since we don't have a clean trace. Differential Revision: https://phabricator.services.mozilla.com/D103057 --- netwerk/cache2/CacheStorageService.cpp | 13 +++++++------ netwerk/cache2/CacheStorageService.h | 9 +++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/netwerk/cache2/CacheStorageService.cpp b/netwerk/cache2/CacheStorageService.cpp index f4e76df530db..30df87a5cf9d 100644 --- a/netwerk/cache2/CacheStorageService.cpp +++ b/netwerk/cache2/CacheStorageService.cpp @@ -64,11 +64,12 @@ typedef nsClassHashtable GlobalEntryTables; */ static GlobalEntryTables* sGlobalEntryTables; -CacheMemoryConsumer::CacheMemoryConsumer(uint32_t aFlags) - : mReportedMemoryConsumption(0), mFlags(aFlags) {} +CacheMemoryConsumer::CacheMemoryConsumer(uint32_t aFlags) { + StoreFlags(aFlags); +} void CacheMemoryConsumer::DoMemoryReport(uint32_t aCurrentSize) { - if (!(mFlags & DONT_REPORT) && CacheStorageService::Self()) { + if (!(LoadFlags() & DONT_REPORT) && CacheStorageService::Self()) { CacheStorageService::Self()->OnMemoryConsumptionChange(this, aCurrentSize); } } @@ -1278,13 +1279,13 @@ void CacheStorageService::OnMemoryConsumptionChange( LOG(("CacheStorageService::OnMemoryConsumptionChange [consumer=%p, size=%u]", aConsumer, aCurrentMemoryConsumption)); - uint32_t savedMemorySize = aConsumer->mReportedMemoryConsumption; + uint32_t savedMemorySize = aConsumer->LoadReportedMemoryConsumption(); if (savedMemorySize == aCurrentMemoryConsumption) return; // Exchange saved size with current one. - aConsumer->mReportedMemoryConsumption = aCurrentMemoryConsumption; + aConsumer->StoreReportedMemoryConsumption(aCurrentMemoryConsumption); - bool usingDisk = !(aConsumer->mFlags & CacheMemoryConsumer::MEMORY_ONLY); + bool usingDisk = !(aConsumer->LoadFlags() & CacheMemoryConsumer::MEMORY_ONLY); bool overLimit = Pool(usingDisk).OnMemoryConsumptionChange( savedMemorySize, aCurrentMemoryConsumption); diff --git a/netwerk/cache2/CacheStorageService.h b/netwerk/cache2/CacheStorageService.h index 107e574701bb..f9f9fafb2771 100644 --- a/netwerk/cache2/CacheStorageService.h +++ b/netwerk/cache2/CacheStorageService.h @@ -18,6 +18,7 @@ #include "nsProxyRelease.h" #include "mozilla/Monitor.h" #include "mozilla/Mutex.h" +#include "mozilla/AtomicBitfields.h" #include "mozilla/Atomics.h" #include "mozilla/TimeStamp.h" #include "nsTArray.h" @@ -43,8 +44,12 @@ class CacheEntryHandle; class CacheMemoryConsumer { private: friend class CacheStorageService; - uint32_t mReportedMemoryConsumption : 30; - uint32_t mFlags : 2; + // clang-format off + MOZ_ATOMIC_BITFIELDS(mAtomicBitfields, 32, ( + (uint32_t, ReportedMemoryConsumption, 30), + (uint32_t, Flags, 2) + )) + // clang-format on private: CacheMemoryConsumer() = delete;