Bug 1625801 - grab the lock when creating and destroying RefMessageBodyService. r=sg

Differential Revision: https://phabricator.services.mozilla.com/D102944
This commit is contained in:
Alexis Beingessner 2021-01-26 17:15:26 +00:00
parent a4315ae315
commit 892361c25c
2 changed files with 6 additions and 3 deletions

View File

@ -17,6 +17,7 @@
namespace mozilla::dom {
// Guards sService and its members.
StaticMutex sRefMessageBodyServiceMutex;
// Raw pointer because the service is kept alive by other objects.
@ -35,16 +36,18 @@ already_AddRefed<RefMessageBodyService> RefMessageBodyService::GetOrCreate() {
RefMessageBodyService* RefMessageBodyService::GetOrCreateInternal(
const StaticMutexAutoLock& aProofOfLock) {
if (!sService) {
sService = new RefMessageBodyService();
sService = new RefMessageBodyService(aProofOfLock);
}
return sService;
}
RefMessageBodyService::RefMessageBodyService() {
RefMessageBodyService::RefMessageBodyService(
const StaticMutexAutoLock& aProofOfLock) {
MOZ_DIAGNOSTIC_ASSERT(sService == nullptr);
}
RefMessageBodyService::~RefMessageBodyService() {
StaticMutexAutoLock lock(sRefMessageBodyServiceMutex);
MOZ_DIAGNOSTIC_ASSERT(sService == this);
sService = nullptr;
}

View File

@ -122,7 +122,7 @@ class RefMessageBodyService final {
void SetMaxCount(const nsID& aID, uint32_t aMaxCount);
private:
RefMessageBodyService();
explicit RefMessageBodyService(const StaticMutexAutoLock& aProofOfLock);
~RefMessageBodyService();
static RefMessageBodyService* GetOrCreateInternal(