1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* some utilities for Gecko to use for Servo initialization and assertions */ 8 9 #ifndef mozilla_ServoUtils_h 10 #define mozilla_ServoUtils_h 11 12 #include "mozilla/Assertions.h" 13 #include "MainThreadUtils.h" 14 15 namespace mozilla { 16 17 // Defined in GeckoBindings.cpp. 18 void InitializeServo(); 19 void ShutdownServo(); 20 void AssertIsMainThreadOrServoFontMetricsLocked(); 21 22 class ServoStyleSet; 23 extern ServoStyleSet* sInServoTraversal; IsInServoTraversal()24inline bool IsInServoTraversal() { 25 // The callers of this function are generally main-thread-only _except_ 26 // for potentially running during the Servo traversal, in which case they may 27 // take special paths that avoid writing to caches and the like. In order 28 // to allow those callers to branch efficiently without checking TLS, we 29 // maintain this static boolean. However, the danger is that those callers 30 // are generally unprepared to deal with non-Servo-but-also-non-main-thread 31 // callers, and are likely to take the main-thread codepath if this function 32 // returns false. So we assert against other non-main-thread callers here. 33 MOZ_ASSERT(sInServoTraversal || NS_IsMainThread()); 34 return sInServoTraversal; 35 } 36 } // namespace mozilla 37 38 #endif // mozilla_ServoUtils_h 39