From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- js/src/vm/HelperThreads.h | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'js/src/vm/HelperThreads.h') diff --git a/js/src/vm/HelperThreads.h b/js/src/vm/HelperThreads.h index 430511d104..3827168f98 100644 --- a/js/src/vm/HelperThreads.h +++ b/js/src/vm/HelperThreads.h @@ -14,6 +14,7 @@ #include "mozilla/Variant.h" #include "js/AllocPolicy.h" +#include "js/HelperThreadAPI.h" #include "js/shadow/Zone.h" #include "js/UniquePtr.h" #include "js/Vector.h" @@ -68,21 +69,44 @@ using UniqueTier2GeneratorTask = UniquePtr; */ extern Mutex gHelperThreadLock MOZ_UNANNOTATED; -class MOZ_RAII AutoLockHelperThreadState : public LockGuard { - using Base = LockGuard; - +// Set of tasks to dispatch when the helper thread state lock is released. +class AutoHelperTaskQueue { public: - explicit AutoLockHelperThreadState() : Base(gHelperThreadLock) {} + ~AutoHelperTaskQueue() { dispatchQueuedTasks(); } + bool hasQueuedTasks() const { + return newTasksToDispatch || finishedTasksToDispatch; + } + void queueTaskToDispatch(JS::DispatchReason reason) const; + void dispatchQueuedTasks(); + + private: + mutable uint32_t newTasksToDispatch = 0; + mutable uint32_t finishedTasksToDispatch = 0; }; -class MOZ_RAII AutoUnlockHelperThreadState : public UnlockGuard { - using Base = UnlockGuard; - +// A lock guard for data protected by the helper thread lock. +// +// This can also queue helper thread tasks to be triggered when the lock is +// released. +class MOZ_RAII AutoLockHelperThreadState + : public AutoHelperTaskQueue, // Must come before LockGuard. + public LockGuard { public: - explicit AutoUnlockHelperThreadState(AutoLockHelperThreadState& locked) - : Base(locked) {} + AutoLockHelperThreadState() : LockGuard(gHelperThreadLock) {} + AutoLockHelperThreadState(const AutoLockHelperThreadState&) = delete; + + private: + friend class UnlockGuard; + void unlock() { + LockGuard::unlock(); + dispatchQueuedTasks(); + } + + friend class GlobalHelperThreadState; }; +using AutoUnlockHelperThreadState = UnlockGuard; + // Create data structures used by helper threads. bool CreateHelperThreadsState(); -- cgit v1.2.3