From 9b5dda0e76cd2afb52b4d32f495063d877743578 Mon Sep 17 00:00:00 2001 From: karurochari Date: Thu, 16 May 2024 02:31:15 +0000 Subject: [PATCH] Added more control over the GC events, and callbacks before the event --- quickjs.c | 3 +++ quickjs.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/quickjs.c b/quickjs.c index 57e907e..224f67a 100644 --- a/quickjs.c +++ b/quickjs.c @@ -241,6 +241,9 @@ struct JSRuntime { struct list_head tmp_obj_list; /* used during GC */ JSGCPhaseEnum gc_phase : 8; size_t malloc_gc_threshold; + BOOL malloc_gc_fix_threshold : 8; + BOOL (*malloc_gc_before_callback)(); + void (*malloc_gc_after_callback)(); #ifdef DUMP_LEAKS struct list_head string_list; /* list of JSString.link */ #endif diff --git a/quickjs.h b/quickjs.h index cb5d528..5a828dd 100644 --- a/quickjs.h +++ b/quickjs.h @@ -302,6 +302,10 @@ JS_EXTERN void JS_SetRuntimeInfo(JSRuntime *rt, const char *info); JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit); JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags); JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold); +JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt); +JS_EXTERN void JS_SetGCThresholdFixed(JSRuntime *rt, BOOL fixed); +JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, BOOL(*fn)()); +JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)()); /* use 0 to disable maximum stack size check */ JS_EXTERN void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size); /* should be called when changing thread to update the stack top value