context: Add API to force GC schedule

There are situations where we cannot run the
GC right away, but we also cannot ignore the
need of running it.

For those cases, add a new private function
that forces GC to happen on idle.
parent a6b6fc13
......@@ -36,6 +36,8 @@ bool _gjs_context_destroying (GjsContext *js_context);
void _gjs_context_schedule_gc_if_needed (GjsContext *js_context);
void _gjs_context_schedule_gc (GjsContext *js_context);
void _gjs_context_exit(GjsContext *js_context,
uint8_t exit_code);
......
......@@ -90,6 +90,7 @@ struct _GjsContext {
uint8_t exit_code;
guint auto_gc_id;
bool force_gc;
std::array<JS::PersistentRootedId*, GJS_STRING_LAST> const_strings;
......@@ -592,21 +593,41 @@ trigger_gc_if_needed (gpointer user_data)
{
GjsContext *js_context = GJS_CONTEXT(user_data);
js_context->auto_gc_id = 0;
gjs_gc_if_needed(js_context->context);
if (js_context->force_gc)
JS_GC(js_context->context);
else
gjs_gc_if_needed(js_context->context);
return G_SOURCE_REMOVE;
}
void
_gjs_context_schedule_gc_if_needed (GjsContext *js_context)
static void
_gjs_context_schedule_gc_internal (GjsContext *js_context,
bool force_gc)
{
if (js_context->auto_gc_id > 0)
return;
g_source_remove(js_context->auto_gc_id);
js_context->force_gc = force_gc;
js_context->auto_gc_id = g_idle_add_full(G_PRIORITY_LOW,
trigger_gc_if_needed,
js_context, NULL);
}
void
_gjs_context_schedule_gc (GjsContext *js_context)
{
_gjs_context_schedule_gc_internal(js_context, true);
}
void
_gjs_context_schedule_gc_if_needed (GjsContext *js_context)
{
_gjs_context_schedule_gc_internal(js_context, false);
}
void
_gjs_context_exit(GjsContext *js_context,
uint8_t exit_code)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment