summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-07-18 03:10:17 (GMT)
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-07-20 01:20:58 (GMT)
commitf3462d99a3dd8d535eda287b000cb035bade522c (patch)
treea1655328cd977dd10a6a2a020b7c57839b4bd1a9 /thread.c
parent9f6a3d030682e9f99c77c2ef31881f9801c3979e (diff)
Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.
Correctly capture thread before releasing GVL and pass as argument to `rb_thread_scheduler_if_nonblocking`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3323
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/thread.c b/thread.c
index e463b72..ed25a96 100644
--- a/thread.c
+++ b/thread.c
@@ -3621,19 +3621,20 @@ VALUE rb_thread_scheduler_set(VALUE thread, VALUE scheduler)
static VALUE
rb_thread_scheduler(VALUE klass)
{
- return rb_current_thread_scheduler();
+ return rb_thread_scheduler_if_nonblocking(rb_thread_current());
}
-VALUE rb_current_thread_scheduler(void)
+VALUE rb_thread_scheduler_if_nonblocking(VALUE thread)
{
- rb_thread_t * th = GET_THREAD();
+ rb_thread_t * th = rb_thread_ptr(thread);
VM_ASSERT(th);
- if (th->blocking == 0)
+ if (th->blocking == 0) {
return th->scheduler;
- else
+ } else {
return Qnil;
+ }
}
static VALUE
@@ -4234,7 +4235,7 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *timeout)
struct waiting_fd wfd;
int state;
- VALUE scheduler = rb_current_thread_scheduler();
+ VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current());
if (scheduler != Qnil) {
VALUE result = rb_funcall(scheduler, id_wait_for_single_fd, 3, INT2NUM(fd), INT2NUM(events),
rb_thread_timeout(timeout)
@@ -4376,7 +4377,7 @@ select_single_cleanup(VALUE ptr)
int
rb_wait_for_single_fd(int fd, int events, struct timeval *timeout)
{
- VALUE scheduler = rb_current_thread_scheduler();
+ VALUE scheduler = rb_thread_scheduler_if_nonblocking(rb_thread_current());
if (scheduler != Qnil) {
VALUE result = rb_funcall(scheduler, id_wait_for_single_fd, 3, INT2NUM(fd), INT2NUM(events),
rb_thread_timeout(timeout)