Bug 1941085 - Elevate SafeOnThisThread to be available in diagnostic builds. r=pbone

Differential Revision: https://phabricator.services.mozilla.com/D240338
This commit is contained in:
Jens Stutte
2025-03-05 08:07:35 +00:00
parent af72d66975
commit 1953551574
2 changed files with 7 additions and 6 deletions

View File

@@ -171,7 +171,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
bool Init(DoLock aDoLock) {
mDoLock = aDoLock;
#ifdef MOZ_DEBUG
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
mThreadId = GetThreadId();
#endif
return Mutex::Init();
@@ -214,7 +214,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
// Return true if we can use this resource from this thread, either because
// we'll use the lock or because this is the only thread that will access the
// protected resource.
#ifdef MOZ_DEBUG
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
bool SafeOnThisThread() const {
return mDoLock == MUST_LOCK || ThreadIdEqual(GetThreadId(), mThreadId);
}
@@ -232,16 +232,16 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
return true;
}
MOZ_ASSERT(ThreadIdEqual(GetThreadId(), mThreadId));
MOZ_ASSERT(SafeOnThisThread());
return false;
}
DoLock mDoLock;
#ifdef MOZ_DEBUG
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
ThreadId mThreadId;
# ifndef XP_WIN
#endif
#if (!defined(XP_WIN) && defined(DEBUG))
bool mDeniedAfterFork = false;
# endif
#endif
};

View File

@@ -4641,6 +4641,7 @@ static inline void arena_dalloc(void* aPtr, size_t aOffset, arena_t* aArena) {
arena_chunk_t* chunk_dealloc_delay = nullptr;
purge_action_t purge_action;
{
MOZ_DIAGNOSTIC_ASSERT(arena->mLock.SafeOnThisThread());
MaybeMutexAutoLock lock(arena->mLock);
arena_chunk_map_t* mapelm = &chunk->map[pageind];
MOZ_RELEASE_ASSERT(