[前][次][番号順一覧][スレッド一覧]

ruby-changes:62877

From: Koichi <ko1@a...>
Date: Thu, 10 Sep 2020 18:44:31 +0900 (JST)
Subject: [ruby-changes:62877] ea78960ee5 (master): sync callable_method_entry()

https://git.ruby-lang.org/ruby.git/commit/?id=ea78960ee5

From ea78960ee5cb78c6aaaaa7091b85066a011c51e9 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 10 Sep 2020 16:51:24 +0900
Subject: sync callable_method_entry()

callable_method_entry() read/write method table structures so that
this function should be synchronized between Ractors.

diff --git a/vm_method.c b/vm_method.c
index 58516b9..0428ae6 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1013,6 +1013,8 @@ complemented_callable_method_entry(VALUE klass, ID id) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1013
 static const rb_callable_method_entry_t *
 cached_callable_method_entry(VALUE klass, ID mid)
 {
+    ASSERT_vm_locking();
+
     struct rb_id_table *cc_tbl = RCLASS_CC_TBL(klass);
     struct rb_class_cc_entries *ccs;
 
@@ -1035,6 +1037,8 @@ cached_callable_method_entry(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1037
 static void
 cache_callable_method_entry(VALUE klass, ID mid, const rb_callable_method_entry_t *cme)
 {
+    ASSERT_vm_locking();
+
     struct rb_id_table *cc_tbl = RCLASS_CC_TBL(klass);
     struct rb_class_cc_entries *ccs;
 
@@ -1054,19 +1058,25 @@ cache_callable_method_entry(VALUE klass, ID mid, const rb_callable_method_entry_ https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1058
 static const rb_callable_method_entry_t *
 callable_method_entry(VALUE klass, ID mid, VALUE *defined_class_ptr)
 {
+    const rb_callable_method_entry_t *cme;
+
     VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_ICLASS));
-    const rb_callable_method_entry_t *cme = cached_callable_method_entry(klass, mid);
+    RB_VM_LOCK_ENTER();
+    {
+        cme = cached_callable_method_entry(klass, mid);
 
-    if (cme) {
-        if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
-    }
-    else {
-        VALUE defined_class;
-        rb_method_entry_t *me = search_method_protect(klass, mid, &defined_class);
-        if (defined_class_ptr) *defined_class_ptr = defined_class;
-        cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
-        if (cme) cache_callable_method_entry(klass, mid, cme);
+        if (cme) {
+            if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
+        }
+        else {
+            VALUE defined_class;
+            rb_method_entry_t *me = search_method_protect(klass, mid, &defined_class);
+            if (defined_class_ptr) *defined_class_ptr = defined_class;
+            cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
+            if (cme) cache_callable_method_entry(klass, mid, cme);
+        }
     }
+    RB_VM_LOCK_LEAVE();
 
     return cme;
 }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]