Files
bun.sh/src/bun.js/bindings/BunJSCEventLoop.cpp
Ben Grant 8d9583dbec Revert to bool parameters
This reverts commit acdbbfcd9a.
2025-03-07 16:31:22 -08:00

41 lines
1.2 KiB
C++

#include "root.h"
#include "BunClientData.h"
#include <JavaScriptCore/VM.h>
#include <JavaScriptCore/Heap.h>
// 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<JSC::JSLock::DropAllLocks> 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);
}