Bug 1403699 Part 1: Unify ServoBindings synchronization primitives into a single RWLock.
MozReview-Commit-ID: GdYLEQHiM1f
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -87,46 +87,44 @@ using namespace mozilla::dom;
RefPtr<type_> result; \
result.swap(mPtr); \
return result.forget(); \
}
#include "mozilla/ServoArcTypeList.h"
SERVO_ARC_TYPE(StyleContext, ServoStyleContext)
#undef SERVO_ARC_TYPE
-static Mutex* sServoFontMetricsLock = nullptr;
-static Mutex* sServoWidgetLock = nullptr;
-static RWLock* sServoLangFontPrefsLock = nullptr;
+static RWLock* sServoFFILock = nullptr;
static
const nsFont*
ThreadSafeGetDefaultFontHelper(const nsPresContext* aPresContext,
nsIAtom* aLanguage, uint8_t aGenericId)
{
bool needsCache = false;
const nsFont* retval;
{
- AutoReadLock guard(*sServoLangFontPrefsLock);
+ AutoReadLock guard(*sServoFFILock);
retval = aPresContext->GetDefaultFont(aGenericId, aLanguage, &needsCache);
}
if (!needsCache) {
return retval;
}
{
- AutoWriteLock guard(*sServoLangFontPrefsLock);
+ AutoWriteLock guard(*sServoFFILock);
retval = aPresContext->GetDefaultFont(aGenericId, aLanguage, nullptr);
}
return retval;
}
void
AssertIsMainThreadOrServoLangFontPrefsCacheLocked()
{
- MOZ_ASSERT(NS_IsMainThread() || sServoLangFontPrefsLock->LockedForWritingByCurrentThread());
+ MOZ_ASSERT(NS_IsMainThread() || sServoFFILock->LockedForWritingByCurrentThread());
}
bool
Gecko_IsInDocument(RawGeckoNodeBorrowed aNode)
{
return aNode->IsInComposedDoc();
}
@@ -855,17 +853,17 @@ Gecko_IsDocumentBody(RawGeckoElementBorr
nscolor
Gecko_GetLookAndFeelSystemColor(int32_t aId,
RawGeckoPresContextBorrowed aPresContext)
{
bool useStandinsForNativeColors = aPresContext && !aPresContext->IsChrome();
nscolor result;
LookAndFeel::ColorID colorId = static_cast<LookAndFeel::ColorID>(aId);
- MutexAutoLock guard(*sServoWidgetLock);
+ AutoWriteLock guard(*sServoFFILock);
LookAndFeel::GetColor(colorId, useStandinsForNativeColors, &result);
return result;
}
bool
Gecko_MatchStringArgPseudo(RawGeckoElementBorrowed aElement,
CSSPseudoClassType aType,
const char16_t* aIdent)
@@ -1299,17 +1297,17 @@ Gecko_nsFont_InitSystem(nsFont* aDest, i
// itself, so this will do.
nsFont* system = new (aDest) nsFont(*defaultVariableFont);
MOZ_RELEASE_ASSERT(system);
*aDest = *defaultVariableFont;
LookAndFeel::FontID fontID = static_cast<LookAndFeel::FontID>(aFontId);
- MutexAutoLock lock(*sServoFontMetricsLock);
+ AutoWriteLock guard(*sServoFFILock);
nsRuleNode::ComputeSystemFont(aDest, fontID, aPresContext, defaultVariableFont);
}
void
Gecko_nsFont_Destroy(nsFont* aDest)
{
aDest->~nsFont();
}
@@ -2348,22 +2346,22 @@ Gecko_nsStyleFont_PrefillDefaultForGener
void
Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* aFont,
RawGeckoPresContextBorrowed aPresContext)
{
nscoord minFontSize;
bool needsCache = false;
{
- AutoReadLock guard(*sServoLangFontPrefsLock);
+ AutoReadLock guard(*sServoFFILock);
minFontSize = aPresContext->MinFontSize(aFont->mLanguage, &needsCache);
}
if (needsCache) {
- AutoWriteLock guard(*sServoLangFontPrefsLock);
+ AutoWriteLock guard(*sServoFFILock);
minFontSize = aPresContext->MinFontSize(aFont->mLanguage, nullptr);
}
nsRuleNode::ApplyMinFontSize(aFont, aPresContext, minFontSize);
}
void
FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs)
@@ -2422,58 +2420,52 @@ void
InitializeServo()
{
URLExtraData::InitDummy();
Servo_Initialize(URLExtraData::Dummy());
gUACacheReporter = new UACacheReporter();
RegisterWeakMemoryReporter(gUACacheReporter);
- sServoFontMetricsLock = new Mutex("Gecko_GetFontMetrics");
- sServoWidgetLock = new Mutex("Servo::WidgetLock");
- sServoLangFontPrefsLock = new RWLock("nsPresContext::GetDefaultFont");
+ sServoFFILock = new RWLock("Servo::FFILock");
}
void
ShutdownServo()
{
- MOZ_ASSERT(sServoFontMetricsLock);
- MOZ_ASSERT(sServoWidgetLock);
- MOZ_ASSERT(sServoLangFontPrefsLock);
+ MOZ_ASSERT(sServoFFILock);
UnregisterWeakMemoryReporter(gUACacheReporter);
gUACacheReporter = nullptr;
- delete sServoFontMetricsLock;
- delete sServoWidgetLock;
- delete sServoLangFontPrefsLock;
+ delete sServoFFILock;
Servo_Shutdown();
}
namespace mozilla {
void
AssertIsMainThreadOrServoFontMetricsLocked()
{
if (!NS_IsMainThread()) {
- MOZ_ASSERT(sServoFontMetricsLock);
- sServoFontMetricsLock->AssertCurrentThreadOwns();
+ MOZ_ASSERT(sServoFFILock &&
+ sServoFFILock->LockedForWritingByCurrentThread());
}
}
} // namespace mozilla
GeckoFontMetrics
Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext,
bool aIsVertical,
const nsStyleFont* aFont,
nscoord aFontSize,
bool aUseUserFontSet)
{
- MutexAutoLock lock(*sServoFontMetricsLock);
+ AutoWriteLock guard(*sServoFFILock);
GeckoFontMetrics ret;
// Getting font metrics can require some main thread only work to be
// done, such as work that needs to touch non-threadsafe refcounted
// objects (like the DOM FontFace/FontFaceSet objects), network loads, etc.
//
// To handle this work, font code checks whether we are in a Servo traversal
// and if so, appends PostTraversalTasks to the current ServoStyleSet