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

ruby-changes:63979

From: Koichi <ko1@a...>
Date: Mon, 7 Dec 2020 08:28:59 +0900 (JST)
Subject: [ruby-changes:63979] 554a7180a0 (master): RB_VM_LOCK_ENTER_CR_LEV

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

From 554a7180a0aad85bee5cb8ed41d99d16dab304e7 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Wed, 2 Dec 2020 04:10:05 +0900
Subject: RB_VM_LOCK_ENTER_CR_LEV

This is variant of RB_VM_LOCK_ENTER_LEV, but accept current racotr's
pointer.

diff --git a/vm_sync.c b/vm_sync.c
index 1ab6c90..8eb2cdf 100644
--- a/vm_sync.c
+++ b/vm_sync.c
@@ -39,13 +39,12 @@ rb_vm_locked_p(void) https://github.com/ruby/ruby/blob/trunk/vm_sync.c#L39
 }
 
 static void
-vm_lock_enter(rb_vm_t *vm, bool locked, unsigned int *lev APPEND_LOCATION_ARGS)
+vm_lock_enter(rb_ractor_t *cr, rb_vm_t *vm, bool locked, unsigned int *lev APPEND_LOCATION_ARGS)
 {
     if (locked) {
         ASSERT_vm_locking();
     }
     else {
-        rb_ractor_t *cr = GET_RACTOR();
 #if RACTOR_CHECK_MODE
         // locking ractor and acquire VM lock will cause deadlock
         VM_ASSERT(cr->locked_by != cr->self);
@@ -128,7 +127,19 @@ MJIT_FUNC_EXPORTED void https://github.com/ruby/ruby/blob/trunk/vm_sync.c#L127
 rb_vm_lock_enter_body(unsigned int *lev APPEND_LOCATION_ARGS)
 {
     rb_vm_t *vm = GET_VM();
-    vm_lock_enter(vm, vm_locked(vm), lev APPEND_LOCATION_PARAMS);
+    if (vm_locked(vm)) {
+        vm_lock_enter(NULL, vm, true, lev APPEND_LOCATION_PARAMS);
+    }
+    else {
+        vm_lock_enter(GET_RACTOR(), vm, false, lev APPEND_LOCATION_PARAMS);
+    }
+}
+
+MJIT_FUNC_EXPORTED void
+rb_vm_lock_enter_body_cr(rb_ractor_t *cr, unsigned int *lev APPEND_LOCATION_ARGS)
+{
+    rb_vm_t *vm = GET_VM();
+    vm_lock_enter(cr, vm, vm_locked(vm), lev APPEND_LOCATION_PARAMS);
 }
 
 MJIT_FUNC_EXPORTED void
@@ -142,7 +153,8 @@ rb_vm_lock_body(LOCATION_ARGS) https://github.com/ruby/ruby/blob/trunk/vm_sync.c#L153
 {
     rb_vm_t *vm = GET_VM();
     ASSERT_vm_unlocking();
-    vm_lock_enter(vm, false, &vm->ractor.sync.lock_rec APPEND_LOCATION_PARAMS);
+
+    vm_lock_enter(GET_RACTOR(), vm, false, &vm->ractor.sync.lock_rec APPEND_LOCATION_PARAMS);
 }
 
 void
diff --git a/vm_sync.h b/vm_sync.h
index 9833f5a..8244b61 100644
--- a/vm_sync.h
+++ b/vm_sync.h
@@ -19,6 +19,9 @@ https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L19
 bool rb_vm_locked_p(void);
 void rb_vm_lock_body(LOCATION_ARGS);
 void rb_vm_unlock_body(LOCATION_ARGS);
+
+struct rb_ractor_struct;
+void rb_vm_lock_enter_body_cr(struct rb_ractor_struct *cr, unsigned int *lev APPEND_LOCATION_ARGS);
 void rb_vm_lock_enter_body(unsigned int *lev APPEND_LOCATION_ARGS);
 void rb_vm_lock_leave_body(unsigned int *lev APPEND_LOCATION_ARGS);
 void rb_vm_barrier(void);
@@ -72,15 +75,29 @@ static inline void https://github.com/ruby/ruby/blob/trunk/vm_sync.h#L75
 rb_vm_lock_leave(unsigned int *lev, const char *file, int line)
 {
     if (rb_multi_ractor_p()) {
-        rb_vm_lock_leave_body(lev APPEND_LOCATION_PARAMS);
+      rb_vm_lock_leave_body(lev APPEND_LOCATION_PARAMS);
     }
 }
 
+static inline void
+rb_vm_lock_enter_cr(struct rb_ractor_struct *cr, unsigned int *levp, const char *file, int line)
+{
+    rb_vm_lock_enter_body_cr(cr, levp APPEND_LOCATION_PARAMS);
+}
+
+static inline void
+rb_vm_lock_leave_cr(struct rb_ractor_struct *cr, unsigned int *levp, const char *file, int line)
+{
+    rb_vm_lock_leave_body(levp APPEND_LOCATION_PARAMS);
+}
+
 #define RB_VM_LOCKED_P()   rb_vm_locked_p()
 
 #define RB_VM_LOCK()       rb_vm_lock(__FILE__, __LINE__)
 #define RB_VM_UNLOCK()     rb_vm_unlock(__FILE__, __LINE__)
 
+#define RB_VM_LOCK_ENTER_CR_LEV(cr, levp) rb_vm_lock_enter_cr(cr, levp, __FILE__, __LINE__)
+#define RB_VM_LOCK_LEAVE_CR_LEV(cr, levp) rb_vm_lock_leave_cr(cr, levp, __FILE__, __LINE__)
 #define RB_VM_LOCK_ENTER_LEV(levp) rb_vm_lock_enter(levp, __FILE__, __LINE__)
 #define RB_VM_LOCK_LEAVE_LEV(levp) rb_vm_lock_leave(levp, __FILE__, __LINE__)
 
-- 
cgit v0.10.2


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

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