Skip to content
Snippets Groups Projects
Commit 6cecb0e3 authored by Jonathan Kew's avatar Jonathan Kew
Browse files

Bug 1878199 - patch 1 - Don't create an additional Mutex in...

Bug 1878199 - patch 1 - Don't create an additional Mutex in FontFaceImpl::Entry, just use the base gfxFontEntry's existing RWLock.  a=dmeehan

No functional change here, just cleanup in preparation for the following patch.
We don't need FontFaceImpl to create a mutex, as there's already a lock (RWLock)
in its base class gfxFontEntry, and we can use that to guard the fields here.

Original Revision: https://phabricator.services.mozilla.com/D207295

Differential Revision: https://phabricator.services.mozilla.com/D208097
parent bfa79cca
No related branches found
No related tags found
No related merge requests found
...@@ -737,7 +737,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) { ...@@ -737,7 +737,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) {
nsTArray<RefPtr<FontFaceImpl>> fontFaces; nsTArray<RefPtr<FontFaceImpl>> fontFaces;
{ {
MutexAutoLock lock(mMutex); AutoReadLock lock(mLock);
fontFaces.SetCapacity(mFontFaces.Length()); fontFaces.SetCapacity(mFontFaces.Length());
for (FontFaceImpl* f : mFontFaces) { for (FontFaceImpl* f : mFontFaces) {
fontFaces.AppendElement(f); fontFaces.AppendElement(f);
...@@ -759,7 +759,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) { ...@@ -759,7 +759,7 @@ void FontFaceImpl::Entry::SetLoadState(UserFontLoadState aLoadState) {
/* virtual */ /* virtual */
void FontFaceImpl::Entry::GetUserFontSets( void FontFaceImpl::Entry::GetUserFontSets(
nsTArray<RefPtr<gfxUserFontSet>>& aResult) { nsTArray<RefPtr<gfxUserFontSet>>& aResult) {
MutexAutoLock lock(mMutex); AutoReadLock lock(mLock);
aResult.Clear(); aResult.Clear();
...@@ -784,7 +784,7 @@ void FontFaceImpl::Entry::GetUserFontSets( ...@@ -784,7 +784,7 @@ void FontFaceImpl::Entry::GetUserFontSets(
/* virtual */ already_AddRefed<gfxUserFontSet> /* virtual */ already_AddRefed<gfxUserFontSet>
FontFaceImpl::Entry::GetUserFontSet() const { FontFaceImpl::Entry::GetUserFontSet() const {
MutexAutoLock lock(mMutex); AutoReadLock lock(mLock);
if (mFontSet) { if (mFontSet) {
return do_AddRef(mFontSet); return do_AddRef(mFontSet);
} }
...@@ -817,7 +817,7 @@ void FontFaceImpl::Entry::CheckUserFontSetLocked() { ...@@ -817,7 +817,7 @@ void FontFaceImpl::Entry::CheckUserFontSetLocked() {
} }
void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners) { void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners) {
MutexAutoLock lock(mMutex); AutoReadLock lock(mLock);
for (FontFaceImpl* f : mFontFaces) { for (FontFaceImpl* f : mFontFaces) {
if (FontFace* owner = f->GetOwner()) { if (FontFace* owner = f->GetOwner()) {
aOwners.Insert(owner); aOwners.Insert(owner);
...@@ -826,13 +826,13 @@ void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners) { ...@@ -826,13 +826,13 @@ void FontFaceImpl::Entry::FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners) {
} }
void FontFaceImpl::Entry::AddFontFace(FontFaceImpl* aFontFace) { void FontFaceImpl::Entry::AddFontFace(FontFaceImpl* aFontFace) {
MutexAutoLock lock(mMutex); AutoWriteLock lock(mLock);
mFontFaces.AppendElement(aFontFace); mFontFaces.AppendElement(aFontFace);
CheckUserFontSetLocked(); CheckUserFontSetLocked();
} }
void FontFaceImpl::Entry::RemoveFontFace(FontFaceImpl* aFontFace) { void FontFaceImpl::Entry::RemoveFontFace(FontFaceImpl* aFontFace) {
MutexAutoLock lock(mMutex); AutoWriteLock lock(mLock);
mFontFaces.RemoveElement(aFontFace); mFontFaces.RemoveElement(aFontFace);
CheckUserFontSetLocked(); CheckUserFontSetLocked();
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "mozilla/dom/FontFaceBinding.h" #include "mozilla/dom/FontFaceBinding.h"
#include "mozilla/FontPropertyTypes.h" #include "mozilla/FontPropertyTypes.h"
#include "mozilla/Maybe.h" #include "mozilla/Maybe.h"
#include "mozilla/Mutex.h" #include "mozilla/RWLock.h"
#include "mozilla/ServoStyleConsts.h" #include "mozilla/ServoStyleConsts.h"
#include "gfxUserFontSet.h" #include "gfxUserFontSet.h"
#include "nsCSSPropertyID.h" #include "nsCSSPropertyID.h"
...@@ -50,7 +50,6 @@ class FontFaceImpl final { ...@@ -50,7 +50,6 @@ class FontFaceImpl final {
Entry(gfxUserFontSet* aFontSet, nsTArray<gfxFontFaceSrc>&& aFontFaceSrcList, Entry(gfxUserFontSet* aFontSet, nsTArray<gfxFontFaceSrc>&& aFontFaceSrcList,
gfxUserFontAttributes&& aAttr) gfxUserFontAttributes&& aAttr)
: gfxUserFontEntry(std::move(aFontFaceSrcList), std::move(aAttr)), : gfxUserFontEntry(std::move(aFontFaceSrcList), std::move(aAttr)),
mMutex("FontFaceImpl::Entry::mMutex"),
mFontSet(aFontSet) {} mFontSet(aFontSet) {}
void SetLoadState(UserFontLoadState aLoadState) override; void SetLoadState(UserFontLoadState aLoadState) override;
...@@ -58,13 +57,13 @@ class FontFaceImpl final { ...@@ -58,13 +57,13 @@ class FontFaceImpl final {
already_AddRefed<gfxUserFontSet> GetUserFontSet() const override; already_AddRefed<gfxUserFontSet> GetUserFontSet() const override;
void CheckUserFontSet() { void CheckUserFontSet() {
MutexAutoLock lock(mMutex); AutoWriteLock lock(mLock);
CheckUserFontSetLocked(); CheckUserFontSetLocked();
} }
#ifdef DEBUG #ifdef DEBUG
bool HasUserFontSet(gfxUserFontSet* aFontSet) const { bool HasUserFontSet(gfxUserFontSet* aFontSet) const {
MutexAutoLock lock(mMutex); AutoReadLock lock(mLock);
return mFontSet == aFontSet; return mFontSet == aFontSet;
} }
#endif #endif
...@@ -74,18 +73,16 @@ class FontFaceImpl final { ...@@ -74,18 +73,16 @@ class FontFaceImpl final {
void FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners); void FindFontFaceOwners(nsTHashSet<FontFace*>& aOwners);
protected: protected:
void CheckUserFontSetLocked() MOZ_REQUIRES(mMutex); void CheckUserFontSetLocked() MOZ_REQUIRES(mLock);
mutable Mutex mMutex;
// Font set which owns this entry; // Font set which owns this entry;
gfxUserFontSet* MOZ_NON_OWNING_REF mFontSet MOZ_GUARDED_BY(mMutex); gfxUserFontSet* MOZ_NON_OWNING_REF mFontSet MOZ_GUARDED_BY(mLock);
// The FontFace objects that use this user font entry. We need to store // The FontFace objects that use this user font entry. We need to store
// an array of these, not just a single pointer, since the user font // an array of these, not just a single pointer, since the user font
// cache can return the same entry for different FontFaces that have // cache can return the same entry for different FontFaces that have
// the same descriptor values and come from the same origin. // the same descriptor values and come from the same origin.
AutoTArray<FontFaceImpl*, 1> mFontFaces MOZ_GUARDED_BY(mMutex); AutoTArray<FontFaceImpl*, 1> mFontFaces MOZ_GUARDED_BY(mLock);
}; };
#ifdef DEBUG #ifdef DEBUG
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment