summaryrefslogtreecommitdiffstats
path: root/js/src/vm/HelperThreads.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-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();