Skip to content

Commit

Permalink
Use a ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Aug 2, 2024
1 parent 0b1624e commit adb6aeb
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/bun.js/bindings/JSCTaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,33 @@ extern "C" void Bun__eventLoop__incrementRefConcurrently(void* bunVM, int delta)

class JSCDeferredWorkTask {
public:
JSCDeferredWorkTask(Ticket ticket, Task&& task)
: ticket(ticket)
JSCDeferredWorkTask(Ref<TicketData> ticket, Task&& task)
: ticket(WTFMove(ticket))
, task(WTFMove(task))
{
ticket->ref();
}

Ticket ticket;
Ref<TicketData> ticket;
Task task;
~JSCDeferredWorkTask()
{
ticket->deref();
}

JSC::VM& vm() const { return ticket->scriptExecutionOwner()->vm(); }

WTF_MAKE_ISO_ALLOCATED(JSCDeferredWorkTask);
};

WTF_MAKE_ISO_ALLOCATED_IMPL(JSCDeferredWorkTask);

static JSC::VM& getVM(Ref<TicketData> ticket)
{
return ticket->scriptExecutionOwner()->vm();
}

static JSC::VM& getVM(Ticket& ticket)
{
return ticket->scriptExecutionOwner()->vm();
}

void JSCTaskScheduler::onAddPendingWork(Ref<TicketData>&& ticket, JSC::DeferredWorkTimer::WorkType kind)
{
JSC::VM& vm = getVM(ticket);
JSC::VM& vm = ticket->scriptExecutionOwner()->vm();
auto clientData = WebCore::clientData(vm);
auto& scheduler = clientData->deferredWorkTimer;
Locker<Lock> holder { scheduler.m_lock };
Expand All @@ -59,7 +54,7 @@ void JSCTaskScheduler::onAddPendingWork(Ref<TicketData>&& ticket, JSC::DeferredW
}
void JSCTaskScheduler::onScheduleWorkSoon(Ticket ticket, Task&& task)
{
auto* job = new JSCDeferredWorkTask(ticket, WTFMove(task));
auto* job = new JSCDeferredWorkTask(*ticket, WTFMove(task));
Bun__queueJSCDeferredWorkTaskConcurrently(WebCore::clientData(getVM(ticket))->bunVM, job);
}

Expand Down Expand Up @@ -95,15 +90,15 @@ static void runPendingWork(void* bunVM, Bun::JSCTaskScheduler& scheduler, JSCDef
holder.unlockEarly();

if (pendingTicket && !pendingTicket->isCancelled()) {
job->task(job->ticket);
job->task(job->ticket.ptr());
}

delete job;
}

extern "C" void Bun__runDeferredWork(Bun::JSCDeferredWorkTask* job)
{
auto& vm = getVM(job->ticket);
auto& vm = job->vm();
auto clientData = WebCore::clientData(vm);

runPendingWork(clientData->bunVM, clientData->deferredWorkTimer, job);
Expand Down

0 comments on commit adb6aeb

Please sign in to comment.