From 178c1b0922dc727897d81d7cfe9c97d5ffa97fd9 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 5 Sep 2020 16:26:24 +1200 Subject: Make Mutex per-Fiber instead of per-Thread * Enables Mutex to be used as synchronization between multiple Fibers of the same Thread. * With a Fiber scheduler we can yield to another Fiber on contended Mutex#lock instead of blocking the entire thread. * This also makes the behavior of Mutex consistent across CRuby, JRuby and TruffleRuby. * [Feature #16792] --- internal/cont.h | 2 ++ internal/scheduler.h | 3 +++ 2 files changed, 5 insertions(+) (limited to 'internal') diff --git a/internal/cont.h b/internal/cont.h index 81874aa5c7..a365cbe978 100644 --- a/internal/cont.h +++ b/internal/cont.h @@ -20,4 +20,6 @@ void rb_fiber_reset_root_local_storage(struct rb_thread_struct *); void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(VALUE), VALUE (*rollback_func)(VALUE)); void rb_fiber_init_mjit_cont(struct rb_fiber_struct *fiber); +VALUE rb_fiberptr_self(struct rb_fiber_struct *fiber); + #endif /* INTERNAL_CONT_H */ diff --git a/internal/scheduler.h b/internal/scheduler.h index f5a41af064..44872e3b10 100644 --- a/internal/scheduler.h +++ b/internal/scheduler.h @@ -17,6 +17,9 @@ VALUE rb_scheduler_timeout(struct timeval *timeout); VALUE rb_scheduler_kernel_sleep(VALUE scheduler, VALUE duration); VALUE rb_scheduler_kernel_sleepv(VALUE scheduler, int argc, VALUE * argv); +VALUE rb_scheduler_mutex_lock(VALUE scheduler, VALUE mutex); +VALUE rb_scheduler_mutex_unlock(VALUE scheduler, VALUE mutex, VALUE fiber); + VALUE rb_scheduler_io_wait(VALUE scheduler, VALUE io, VALUE events, VALUE timeout); VALUE rb_scheduler_io_wait_readable(VALUE scheduler, VALUE io); VALUE rb_scheduler_io_wait_writable(VALUE scheduler, VALUE io); -- cgit v1.2.3