Add infallibleInit method to ThreadLocal and AssertOwns methods to Mutex

This commit is contained in:
ownedbywuigi 2026-03-30 00:30:51 +01:00
commit 32e0f7f621
2 changed files with 26 additions and 0 deletions

View file

@ -132,6 +132,8 @@ public:
MOZ_MUST_USE inline bool init();
inline void infallibleInit();
inline T get() const;
inline void set(const T aValue);
@ -171,6 +173,15 @@ ThreadLocal<T>::init()
#endif
}
template<typename T>
inline void
ThreadLocal<T>::infallibleInit()
{
if (!init()) {
MOZ_CRASH("unable to initialize ThreadLocal");
}
}
template<typename T>
inline T
ThreadLocal<T>::get() const

View file

@ -172,6 +172,21 @@ public:
mLock->Unlock();
}
// Assert that the current thread owns the lock right now.
void AssertOwns() const
{
mLock->AssertCurrentThreadOwns();
}
// Assert that aLock is the lock passed to the constructor and that the
// current thread owns it. Pointer equality alone is not sufficient because
// lock ownership may be temporarily released with BaseAutoUnlock.
void AssertOwns(const T& aLock) const
{
MOZ_ASSERT(&aLock == mLock);
AssertOwns();
}
private:
BaseAutoLock();
BaseAutoLock(BaseAutoLock&);