ruby-changes:63975
From: Koichi <ko1@a...>
Date: Mon, 7 Dec 2020 08:28:57 +0900 (JST)
Subject: [ruby-changes:63975] b67b24d0f5 (master): ruby_single_main_ractor for single ractor mode
https://git.ruby-lang.org/ruby.git/commit/?id=b67b24d0f5 From b67b24d0f5e78481e6a306881b6858f0dec996ba Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Wed, 2 Dec 2020 03:37:56 +0900 Subject: ruby_single_main_ractor for single ractor mode ruby_multi_ractor was a flag that indicates the interpreter doesn't make any additional ractors (single ractor mode). Instead of boolean flag, ruby_single_main_ractor pointer is introduced which keeps main ractor's pointer if single ractor mode. If additional ractors are created, ruby_single_main_ractor becomes NULL. diff --git a/ractor.c b/ractor.c index d7a9c85..1ed0272 100644 --- a/ractor.c +++ b/ractor.c @@ -30,8 +30,10 @@ rb_ractor_error_class(void) https://github.com/ruby/ruby/blob/trunk/ractor.c#L30 } RUBY_SYMBOL_EXPORT_BEGIN + // to share with MJIT -bool ruby_multi_ractor; +rb_ractor_t *ruby_single_main_ractor; + RUBY_SYMBOL_EXPORT_END static void vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *r, const char *file, int line); @@ -1158,9 +1160,9 @@ vm_insert_ractor(rb_vm_t *vm, rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1160 else { vm_ractor_blocking_cnt_inc(vm, r, __FILE__, __LINE__); - RUBY_DEBUG_LOG("ruby_multi_ractor=true", 0); // enable multi-ractor mode - ruby_multi_ractor = true; + RUBY_DEBUG_LOG("enable multi-ractor mode", 0); + ruby_single_main_ractor = NULL; if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL)) { rb_warn("Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues."); @@ -1217,6 +1219,7 @@ rb_ractor_main_alloc(void) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1219 r->id = ++ractor_last_id; r->loc = Qnil; r->name = Qnil; + ruby_single_main_ractor = r; return r; } diff --git a/ractor_core.h b/ractor_core.h index b029515..9f87f15 100644 --- a/ractor_core.h +++ b/ractor_core.h @@ -176,12 +176,10 @@ void rb_ractor_local_storage_delkey(rb_ractor_local_key_t key); https://github.com/ruby/ruby/blob/trunk/ractor_core.h#L176 RUBY_SYMBOL_EXPORT_END -RUBY_EXTERN bool ruby_multi_ractor; - static inline bool rb_ractor_main_p(void) { - if (!ruby_multi_ractor) { + if (ruby_single_main_ractor) { return true; } else { diff --git a/vm_core.h b/vm_core.h index 5ddd7b4..6b975ac 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1799,11 +1799,18 @@ rb_current_thread(void) https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1799 return rb_ec_thread_ptr(ec); } +extern struct rb_ractor_struct *ruby_single_main_ractor; // ractor.c + static inline rb_ractor_t * rb_current_ractor(void) { - const rb_execution_context_t *ec = GET_EC(); - return rb_ec_ractor_ptr(ec); + if (ruby_single_main_ractor) { + return ruby_single_main_ractor; + } + else { + const rb_execution_context_t *ec = GET_EC(); + return rb_ec_ractor_ptr(ec); + } } static inline rb_vm_t * diff --git a/vm_sync.h b/vm_sync.h index 204bcd6..9833f5a 100644 --- a/vm_sync.h +++ b/vm_sync.h @@ -3,7 +3,6 @@ https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L3 #define RUBY_VM_SYNC_H #include "vm_debug.h" -RUBY_EXTERN bool ruby_multi_ractor; #if USE_RUBY_DEBUG_LOG #define LOCATION_ARGS const char *file, int line @@ -29,10 +28,12 @@ void rb_vm_barrier(void); https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L28 #include "vm_core.h" #endif +extern struct rb_ractor_struct *ruby_single_main_ractor; // ractor.c + static inline bool rb_multi_ractor_p(void) { - if (LIKELY(!ruby_multi_ractor)) { + if (LIKELY(ruby_single_main_ractor)) { // 0 on boot time. RUBY_ASSERT(GET_VM()->ractor.cnt <= 1); return false; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/