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:
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user