summaryrefslogtreecommitdiff
path: root/vm_sync.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-10-14 14:21:57 +0900
committerKoichi Sasada <ko1@atdot.net>2020-10-14 16:36:55 +0900
commitae693fff748c68ca2500bbc2c0a8802d50f269dc (patch)
treee96405ea3df4d2c03dce9cbe52503118005fc346 /vm_sync.c
parent0714cb760c2b16f7d40e563b6ab9894553baf32c (diff)
fix releasing timing.
(1) recorded_lock_rec > current_lock_rec should not be occurred on rb_ec_vm_lock_rec_release(). (2) should be release VM lock at EXEC_TAG(), not POP_TAG(). (3) some refactoring.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3655
Diffstat (limited to 'vm_sync.c')
-rw-r--r--vm_sync.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/vm_sync.c b/vm_sync.c
index 6b17ce83b5..b670984a13 100644
--- a/vm_sync.c
+++ b/vm_sync.c
@@ -116,6 +116,7 @@ vm_lock_leave(rb_vm_t *vm, unsigned int *lev APPEND_LOCATION_ARGS)
VM_ASSERT(vm->ractor.sync.lock_rec == *lev);
vm->ractor.sync.lock_rec--;
+ *lev = vm->ractor.sync.lock_rec;
if (vm->ractor.sync.lock_rec == 0) {
vm->ractor.sync.lock_owner = NULL;
@@ -248,21 +249,19 @@ rb_vm_barrier(void)
}
void
-rb_ec_vm_lock_rec_release(rb_execution_context_t *ec, int recorded_lock_rec)
+rb_ec_vm_lock_rec_release(const rb_execution_context_t *ec,
+ unsigned int recorded_lock_rec,
+ unsigned int current_lock_rec)
{
- int current_lock_rec = rb_ec_vm_lock_rec(ec);
- unsigned int lev;
-
- bp();
+ VM_ASSERT(recorded_lock_rec != current_lock_rec);
- if (recorded_lock_rec > current_lock_rec) {
- for (; recorded_lock_rec > current_lock_rec; current_lock_rec++) {
- RB_VM_LOCK_ENTER_LEV(&lev);
- }
+ if (UNLIKELY(recorded_lock_rec > current_lock_rec)) {
+ rb_bug("unexpected situation - recordd:%u current:%u",
+ recorded_lock_rec, current_lock_rec);
}
else {
- for (; recorded_lock_rec < current_lock_rec; current_lock_rec--) {
- RB_VM_LOCK_LEAVE_LEV(&lev);
+ while (recorded_lock_rec < current_lock_rec) {
+ RB_VM_LOCK_LEAVE_LEV(&current_lock_rec);
}
}