mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
41 lines
1.2 KiB
C++
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);
|
|
}
|