Skip to content

Commit

Permalink
Handle the functions being native for rb_thread_call_without_gvl()
Browse files Browse the repository at this point in the history
* Fixes #2090
  • Loading branch information
eregon committed Oct 10, 2020
1 parent 294c55d commit 80d2498
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Compatibility:
* `File#path` now returns a new mutable String on every call like MRI (#2115).
* Avoid infinite recursion when redefining `Warning#warn` and calling `Kernel#warn` (#2109).
* Convert objects with `#to_path` in `$LOAD_PATH` (#2119).
* Handle the functions being native for `rb_thread_call_without_gvl()` (#2090).

Performance:

Expand Down
34 changes: 32 additions & 2 deletions src/main/c/cext/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,41 @@ void *rb_thread_call_with_gvl(gvl_call function, void *data1) {
return polyglot_invoke(RUBY_CEXT, "rb_thread_call_with_gvl", function, data1);
}

struct gvl_call_data {
gvl_call function;
void* data;
};

struct unblock_function_data {
rb_unblock_function_t* function;
void* data;
};

static void* call_gvl_call_function(void *data) {
struct gvl_call_data* s = (struct gvl_call_data*) data;
return s->function(s->data);
}

static void call_unblock_function(void *data) {
struct unblock_function_data* s = (struct unblock_function_data*) data;
s->function(s->data);
}

void *rb_thread_call_without_gvl(gvl_call function, void *data1, rb_unblock_function_t *unblock_function, void *data2) {
// wrap functions to handle native functions
struct gvl_call_data call_struct = { function, data1 };
struct unblock_function_data unblock_struct = { unblock_function, data2 };

rb_unblock_function_t *wrapped_unblock_function;
if (unblock_function == RUBY_UBF_IO) {
unblock_function = (rb_unblock_function_t*) rb_tr_unwrap(Qnil);
wrapped_unblock_function = (rb_unblock_function_t*) rb_tr_unwrap(Qnil);
} else {
wrapped_unblock_function = call_unblock_function;
}
return polyglot_invoke(RUBY_CEXT, "rb_thread_call_without_gvl", function, data1, unblock_function, data2);

return polyglot_invoke(RUBY_CEXT, "rb_thread_call_without_gvl",
call_gvl_call_function, &call_struct,
wrapped_unblock_function, &unblock_struct);
}

ID rb_frame_this_func(void) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/truffleruby/core/thread/ThreadNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ protected Object call(RubyThread thread, Object function, Object arg, Object unb
} finally {
thread.status = status;
actionHolder.restore(oldAction);

}
}

Expand Down

0 comments on commit 80d2498

Please sign in to comment.