Skip to content

Commit

Permalink
Update JSCTaskScheduler.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Aug 2, 2024
1 parent 24cbc78 commit b1c76bc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bun.js/bindings/JSCTaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ void JSCTaskScheduler::onScheduleWorkSoon(Ticket ticket, Task&& task)

void JSCTaskScheduler::onCancelPendingWork(Ticket ticket)
{
auto& scheduler = WebCore::clientData(getVM(ticket))->deferredWorkTimer;
JSC::VM& vm = getVM(ticket);
auto* clientData = WebCore::clientData(vm);
auto* bunVM = clientData->bunVM;
auto& scheduler = clientData->deferredWorkTimer;

Locker<Lock> holder { scheduler.m_lock };
bool isKeepingEventLoopAlive = scheduler.m_pendingTicketsKeepingEventLoopAlive.removeIf([ticket](auto pendingTicket) {
return pendingTicket.ptr() == ticket;
});
// -- At this point, ticket may be an invalid pointer.

if (isKeepingEventLoopAlive) {
holder.unlockEarly();
JSC::VM& vm = getVM(ticket);
Bun__eventLoop__incrementRefConcurrently(WebCore::clientData(vm)->bunVM, -1);
Bun__eventLoop__incrementRefConcurrently(bunVM, -1);
} else {
scheduler.m_pendingTicketsOther.removeIf([ticket](auto pendingTicket) {
return pendingTicket.ptr() == ticket;
Expand Down

0 comments on commit b1c76bc

Please sign in to comment.