From c3ba3fa8d01aa3970dc1f4e3dc0090ae171e9e35 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Wed, 14 Oct 2020 02:03:21 +0900 Subject: support exception when lock_rec > 0 If a ractor getting a VM lock (monitor) raises an exception, unlock can be skipped. To release VM lock correctly on exception (or other jumps with JUMP_TAG), EC_POP_TAG() releases VM lock. --- vm_sync.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'vm_sync.c') diff --git a/vm_sync.c b/vm_sync.c index e3d0ffed15..6b17ce83b5 100644 --- a/vm_sync.c +++ b/vm_sync.c @@ -246,3 +246,25 @@ rb_vm_barrier(void) } } } + +void +rb_ec_vm_lock_rec_release(rb_execution_context_t *ec, int recorded_lock_rec) +{ + int current_lock_rec = rb_ec_vm_lock_rec(ec); + unsigned int lev; + + bp(); + + if (recorded_lock_rec > current_lock_rec) { + for (; recorded_lock_rec > current_lock_rec; current_lock_rec++) { + RB_VM_LOCK_ENTER_LEV(&lev); + } + } + else { + for (; recorded_lock_rec < current_lock_rec; current_lock_rec--) { + RB_VM_LOCK_LEAVE_LEV(&lev); + } + } + + VM_ASSERT(recorded_lock_rec == rb_ec_vm_lock_rec(ec)); +} -- cgit v1.2.3