Bug 1356103 - Part 2: Add functions to assert the Servo font metrics mutex is locked. r=bholley
authorCameron McCormack <cam@mcc.id.au>
Sun, 30 Apr 2017 13:15:42 +0800
changeset 573130 81df1087642e447f111b9af6f04c86dcf1860720
parent 573129 034d72052f8c9df2e8627836c64516a7478df20e
child 573131 8ec2cc2ac751b11a917cfda65381f52cbce30d81
push id57306
push userbmo:emilio+bugs@crisal.io
push dateFri, 05 May 2017 10:08:55 +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; }