Bug 1356103 - Part 2: Add functions to assert the Servo font metrics mutex is locked. r=bholley draft
authorCameron McCormack <cam@mcc.id.au>
Sun, 30 Apr 2017 13:15:42 +0800
changeset 572427 ec12098f89788478de5327d40345d2733747ac48
parent 572426 a230d595736d0e7c3f68c3a424fd9dc4ef74f384
child 572428 eec7033f4c3508c68169bd4e9419c1f40581eaf6
child 572575 5d58bfbab0ad0d11c5bfc500e46bc0307beb98a4
push id57070
push userbmo:cam@mcc.id.au
push dateThu, 04 May 2017 06:37:07 +0000
reviewersbholley
bugs1356103
milestone55.0a1
Bug 1356103 - Part 2: Add functions to assert the Servo font metrics mutex is locked. r=bholley MozReview-Commit-ID: QtydYSYvxW
layout/style/ServoBindings.cpp
layout/style/ServoUtils.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1816,16 +1816,29 @@ InitializeServo()
 
 void
 ShutdownServo()
 {
   delete sServoFontMetricsLock;
   Servo_Shutdown();
 }
 
+namespace mozilla {
+
+void
+AssertIsMainThreadOrServoFontMetricsLocked()
+{
+  if (!NS_IsMainThread()) {
+    MOZ_ASSERT(sServoFontMetricsLock);
+    sServoFontMetricsLock->AssertCurrentThreadOwns();
+  }
+}
+
+} // namespace mozilla
+
 GeckoFontMetrics
 Gecko_GetFontMetrics(RawGeckoPresContextBorrowed aPresContext,
                      bool aIsVertical,
                      const nsStyleFont* aFont,
                      nscoord aFontSize,
                      bool aUseUserFontSet)
 {
   // This function is still unsafe due to frobbing DOM and network
--- a/layout/style/ServoUtils.h
+++ b/layout/style/ServoUtils.h
@@ -6,16 +6,23 @@
 
 /* some utilities for stylo */
 
 #ifndef mozilla_ServoUtils_h
 #define mozilla_ServoUtils_h
 
 #include "mozilla/TypeTraits.h"
 
+namespace mozilla {
+
+// Defined in ServoBindings.cpp.
+void AssertIsMainThreadOrServoFontMetricsLocked();
+
+} // namespace mozilla
+
 #ifdef MOZ_STYLO
 # define MOZ_DECL_STYLO_CHECK_METHODS \
   bool IsGecko() const { return !IsServo(); } \
   bool IsServo() const { return mType == StyleBackendType::Servo; }
 #else
 # define MOZ_DECL_STYLO_CHECK_METHODS \
   bool IsGecko() const { return true; } \
   bool IsServo() const { return false; }