Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions ext/mini_racer_extension/mini_racer_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,21 @@ void v8_get_flags(char **p, size_t *n)
rb_thread_lock_native_thread();
}

// Blocks until the V8 thread finishes booting the isolate, which includes
// snapshot deserialization (v8::Isolate::New) and safe-context setup. None of
// that touches Ruby objects -- the snapshot is a plain C buffer already copied
// into |c->snapshot| -- so we release the GVL while waiting, letting other Ruby
// threads (e.g. a background pool refilling more contexts) truly run meanwhile.
static void *context_boot_wait(void *arg)
{
Context *c;

c = arg;
barrier_wait(&c->early_init);
barrier_wait(&c->late_init);
return NULL;
}

static VALUE context_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE kwargs, a, k, v;
Expand Down Expand Up @@ -1670,8 +1685,7 @@ static VALUE context_initialize(int argc, VALUE *argv, VALUE self)
pthread_attr_destroy(&attr);
if (r)
goto fail;
barrier_wait(&c->early_init);
barrier_wait(&c->late_init);
rb_thread_call_without_gvl(context_boot_wait, c, NULL, NULL);
}
return Qnil;
fail:
Expand Down
Loading