summaryrefslogtreecommitdiffstats
path: root/js/src/vm/HelperThreads.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /js/src/vm/HelperThreads.h
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/vm/HelperThreads.h')
-rw-r--r--js/src/vm/HelperThreads.h42
1 files changed, 33 insertions, 9 deletions
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<Tier2GeneratorTask>;
*/
extern Mutex gHelperThreadLock MOZ_UNANNOTATED;
-class MOZ_RAII AutoLockHelperThreadState : public LockGuard<Mutex> {
- using Base = LockGuard<Mutex>;
-
+// 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<Mutex> {
- using Base = UnlockGuard<Mutex>;
-
+// 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<Mutex> {
public:
- explicit AutoUnlockHelperThreadState(AutoLockHelperThreadState& locked)
- : Base(locked) {}
+ AutoLockHelperThreadState() : LockGuard<Mutex>(gHelperThreadLock) {}
+ AutoLockHelperThreadState(const AutoLockHelperThreadState&) = delete;
+
+ private:
+ friend class UnlockGuard<AutoLockHelperThreadState>;
+ void unlock() {
+ LockGuard<Mutex>::unlock();
+ dispatchQueuedTasks();
+ }
+
+ friend class GlobalHelperThreadState;
};
+using AutoUnlockHelperThreadState = UnlockGuard<AutoLockHelperThreadState>;
+
// Create data structures used by helper threads.
bool CreateHelperThreadsState();