Backed out 4 changesets (bug 1875768) for causing cppunittest-1proc failures CLOSED TREE

Backed out changeset add6151e17ee (bug 1875768)
Backed out changeset 01fa7e793e87 (bug 1875768)
Backed out changeset 99f0bce25b22 (bug 1875768)
Backed out changeset f6847957c1cc (bug 1875768)
This commit is contained in:
Sandor Molnar 2024-06-07 08:18:50 +03:00
Родитель 9c113718ee
Коммит 10e7fbf7a5
3 изменённых файлов: 12 добавлений и 47 удалений

Просмотреть файл

@ -153,13 +153,9 @@ typedef Mutex StaticMutex;
#ifdef XP_WIN
typedef DWORD ThreadId;
inline ThreadId GetThreadId() { return GetCurrentThreadId(); }
inline bool ThreadIdEqual(ThreadId a, ThreadId b) { return a == b; }
#else
typedef pthread_t ThreadId;
inline ThreadId GetThreadId() { return pthread_self(); }
inline bool ThreadIdEqual(ThreadId a, ThreadId b) {
return pthread_equal(a, b);
}
#endif
class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
@ -216,7 +212,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
// protected resource.
#ifdef MOZ_DEBUG
bool SafeOnThisThread() const {
return mDoLock == MUST_LOCK || ThreadIdEqual(GetThreadId(), mThreadId);
return mDoLock == MUST_LOCK || GetThreadId() == mThreadId;
}
#endif
@ -232,7 +228,7 @@ class MOZ_CAPABILITY("mutex") MaybeMutex : public Mutex {
return true;
}
MOZ_ASSERT(ThreadIdEqual(GetThreadId(), mThreadId));
MOZ_ASSERT(GetThreadId() == mThreadId);
return false;
}

Просмотреть файл

@ -1392,8 +1392,7 @@ class ArenaCollection {
// We're running on the main thread which is set by a call to SetMainThread().
bool IsOnMainThread() const {
return mMainThreadId.isSome() &&
ThreadIdEqual(mMainThreadId.value(), GetThreadId());
return mMainThreadId.isSome() && mMainThreadId.value() == GetThreadId();
}
// We're running on the main thread or SetMainThread() has never been called.
@ -1402,10 +1401,11 @@ class ArenaCollection {
}
// After a fork set the new thread ID in the child.
void ResetMainThread() {
// The post fork handler in the child can run from a MacOS worker thread,
// so we can't set our main thread to it here. Instead we have to clear it.
mMainThreadId = Nothing();
void PostForkFixMainThread() {
if (mMainThreadId.isSome()) {
// Only if the main thread has been defined.
mMainThreadId = Some(GetThreadId());
}
}
void SetMainThread() {
@ -1550,9 +1550,6 @@ static bool malloc_init_hard();
FORK_HOOK void _malloc_prefork(void);
FORK_HOOK void _malloc_postfork_parent(void);
FORK_HOOK void _malloc_postfork_child(void);
# ifdef XP_DARWIN
FORK_HOOK void _malloc_postfork(void);
# endif
#endif
// End forward declarations.
@ -5181,23 +5178,13 @@ inline void MozJemalloc::moz_set_max_dirty_page_modifier(int32_t aModifier) {
// state for the child is if fork is called from the main thread only. Or the
// child must not use them, eg it should call exec(). We attempt to prevent the
// child for accessing these arenas by refusing to re-initialise them.
//
// This is only accessed in the fork handlers while gArenas.mLock is held.
static pthread_t gForkingThread;
# ifdef XP_DARWIN
// This is only accessed in the fork handlers while gArenas.mLock is held.
static mach_port_t gForkingProcess;
# endif
FORK_HOOK
void _malloc_prefork(void) MOZ_NO_THREAD_SAFETY_ANALYSIS {
// Acquire all mutexes in a safe order.
gArenas.mLock.Lock();
gForkingThread = pthread_self();
# ifdef XP_DARWIN
gForkingProcess = mach_task_self();
# endif
for (auto arena : gArenas.iter()) {
if (arena->mLock.LockIsEnabled()) {
@ -5228,9 +5215,6 @@ void _malloc_postfork_parent(void) MOZ_NO_THREAD_SAFETY_ANALYSIS {
FORK_HOOK
void _malloc_postfork_child(void) {
// Do this before iterating over the arenas.
gArenas.ResetMainThread();
// Reinitialize all mutexes, now that fork() has completed.
huge_mtx.Init();
@ -5240,24 +5224,10 @@ void _malloc_postfork_child(void) {
arena->mLock.Reinit(gForkingThread);
}
gArenas.PostForkFixMainThread();
gArenas.mLock.Init();
}
# ifdef XP_DARWIN
FORK_HOOK
void _malloc_postfork(void) {
// On MacOS we need to check if this is running in the parent or child
// process.
bool is_in_parent = mach_task_self() == gForkingProcess;
gForkingProcess = 0;
if (is_in_parent) {
_malloc_postfork_parent();
} else {
_malloc_postfork_child();
}
}
# endif // XP_DARWIN
#endif // ! XP_WIN
#endif // XP_WIN
// End library-private functions.
// ***************************************************************************

Просмотреть файл

@ -232,9 +232,8 @@ static void zone_print(malloc_zone_t* zone, boolean_t verbose) {}
static void zone_log(malloc_zone_t* zone, void* address) {}
// On Darwin the postfork handler is called in both the parent and the child.
extern void _malloc_prefork(void);
extern void _malloc_postfork(void);
extern void _malloc_postfork_child(void);
static void zone_force_lock(malloc_zone_t* zone) {
// /!\ This calls into mozjemalloc. It works because we're linked in the
@ -245,7 +244,7 @@ static void zone_force_lock(malloc_zone_t* zone) {
static void zone_force_unlock(malloc_zone_t* zone) {
// /!\ This calls into mozjemalloc. It works because we're linked in the
// same library.
_malloc_postfork();
_malloc_postfork_child();
}
static void zone_statistics(malloc_zone_t* zone, malloc_statistics_t* stats) {