#include "root.h" #include "BunClientData.h" #include #include // It would be nicer to construct a DropAllLocks in us_loop_run_bun_tick (the only function that // uses onBeforeWait and onAfterWait), but that code is in C. We use an optional as that lets us // check whether it's initialized. static thread_local std::optional drop_all_locks { std::nullopt }; extern "C" void WTFTimer__runIfImminent(void* bun_vm); extern "C" void Bun__JSC_onBeforeWait(JSC::VM* _Nonnull vm) { ASSERT(!drop_all_locks.has_value()); bool previouslyHadAccess = vm->heap.hasHeapAccess(); drop_all_locks.emplace(*vm); if (previouslyHadAccess) { vm->heap.releaseAccess(); } } extern "C" void Bun__JSC_onAfterWait(JSC::VM* _Nonnull vm, bool hasMoreEventLoopWorkToDo) { vm->heap.acquireAccess(); drop_all_locks.reset(); if (hasMoreEventLoopWorkToDo) { auto& gcController = WebCore::clientData(*vm)->gcController(); gcController.setHasMoreEventLoopWorkToDo(true); } } extern "C" void Bun__JSC_onDidRunCallbacks(JSC::VM* _Nonnull vm) { auto& gcController = WebCore::clientData(*vm)->gcController(); gcController.setHasMoreEventLoopWorkToDo(false); }