Skip to content

Commit

Permalink
core: workaround libuv change in behavior
Browse files Browse the repository at this point in the history
In libuv/libuv#3686 libuv changed when timers
run respective to check handles.

Change the way we run the loop by running it again if necessary, untill
there is no more work to do of the loop has been stopped.

Fixes: #443
  • Loading branch information
saghul committed Dec 18, 2023
1 parent 5564ac3 commit e51f519
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ JSValue tjs_throw_errno(JSContext *ctx, int err);
JSValue tjs_new_pipe(JSContext *ctx);
uv_stream_t *tjs_pipe_get_stream(JSContext *ctx, JSValueConst obj);

void tjs_execute_jobs(JSContext *ctx);

JSModuleDef *tjs__load_builtin(JSContext *ctx, const char *name);
int tjs__load_file(JSContext *ctx, DynBuf *dbuf, const char *filename);
JSModuleDef *tjs_module_loader(JSContext *ctx, const char *module_name, void *opaque);
Expand Down
4 changes: 0 additions & 4 deletions src/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ static void uv__timer_cb(uv_timer_t *handle) {
TJSTimer *th = handle->data;
CHECK_NOT_NULL(th);

/* Timer always executes before check phase in libuv,
so clear the microtask queue here before running setTimeout macrotasks */
tjs_execute_jobs(th->ctx);

call_timer(th);
if (!th->interval)
clear_timer(th);
Expand Down
12 changes: 7 additions & 5 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static void uv__prepare_cb(uv_prepare_t *handle) {
uv__maybe_idle(qrt);
}

void tjs_execute_jobs(JSContext *ctx) {
static void tjs__execute_jobs(JSContext *ctx) {
JSContext *ctx1;
int err;

Expand All @@ -322,7 +322,7 @@ static void uv__check_cb(uv_check_t *handle) {
TJSRuntime *qrt = handle->data;
CHECK_NOT_NULL(qrt);

tjs_execute_jobs(qrt->ctx);
tjs__execute_jobs(qrt->ctx);

uv__maybe_idle(qrt);
}
Expand All @@ -347,9 +347,11 @@ int TJS_Run(TJSRuntime *qrt) {
if (ret != 0)
return ret;

uv__maybe_idle(qrt);

uv_run(&qrt->loop, UV_RUN_DEFAULT);
int r;
do {
uv__maybe_idle(qrt);
r = uv_run(&qrt->loop, UV_RUN_DEFAULT);
} while (r == 0 && JS_IsJobPending(qrt->rt));

JSValue exc = JS_GetException(qrt->ctx);
if (!JS_IsNull(exc)) {
Expand Down

0 comments on commit e51f519

Please sign in to comment.