Bug 1865774 - Add WorkerPrivate::mWorkerLoopIsIdle to indicate the Worker is idle and could be GCed. r=asuth

After this patch, the Worker can be GCed while it is idle for events.

I want to point out the difference from the BusyCount implementation.
Compared to the BusyCount implementation, BusyCount implementation allows the Worker to be GCed during WorkerRunnable execution iff the WorkeRunnable does not modify BusyCount.

Differential Revision: https://phabricator.services.mozilla.com/D194333
This commit is contained in:
Eden Chuang
2023-11-22 16:18:34 +00:00
parent bf95c282c6
commit 08e3c42781
2 changed files with 8 additions and 1 deletions

View File

@@ -3204,7 +3204,11 @@ void WorkerPrivate::DoRunLoop(JSContext* aCx) {
// an event running for a very long time.
thread->SetRunningEventDelay(TimeDuration(), TimeStamp());
mWorkerLoopIsIdle = true;
WaitForWorkerEvents();
mWorkerLoopIsIdle = false;
}
auto result = ProcessAllControlRunnablesLocked();
@@ -4364,7 +4368,7 @@ bool WorkerPrivate::IsEligibleForCC() {
return mMainThreadEventTarget->IsEmpty() &&
mMainThreadEventTargetForMessaging->IsEmpty() &&
mMainThreadDebuggeeEventTarget->IsEmpty() && mCCFlagSaysEligible &&
!hasShutdownTasks && !hasPendingEvents;
!hasShutdownTasks && !hasPendingEvents && mWorkerLoopIsIdle;
}
void WorkerPrivate::CancelAllTimeouts() {

View File

@@ -1617,6 +1617,9 @@ class WorkerPrivate final
bool mShutdownTasksRun MOZ_GUARDED_BY(mMutex) = false;
bool mCCFlagSaysEligible MOZ_GUARDED_BY(mMutex){true};
// The flag indicates if the worke is idle for events in the main event loop.
bool mWorkerLoopIsIdle MOZ_GUARDED_BY(mMutex){false};
};
class AutoSyncLoopHolder {