[Semaphore] Remove duplicate PID and time settings

This commit is contained in:
Yuke Peng
2024-08-30 13:59:37 +08:00
committed by Tate, Hongliang Tian
parent 3297976700
commit d88d8fd307

View File

@ -106,10 +106,8 @@ impl Semaphore {
let mut current_val = self.val.lock(); let mut current_val = self.val.lock();
*current_val = val; *current_val = val;
self.latest_modified_pid
.store(current_pid, Ordering::Relaxed);
self.update_pending_ops(current_val); self.update_pending_ops(current_val, current_pid);
Ok(()) Ok(())
} }
@ -191,11 +189,7 @@ impl Semaphore {
} }
*val = new_val; *val = new_val;
self.latest_modified_pid self.update_pending_ops(val, current_pid);
.store(current_pid, Ordering::Relaxed);
self.update_otime();
self.update_pending_ops(val);
return Ok(()); return Ok(());
} else if zero_condition { } else if zero_condition {
return Ok(()); return Ok(());
@ -249,7 +243,7 @@ impl Semaphore {
} }
/// Updates pending ops after the val changed. /// Updates pending ops after the val changed.
fn update_pending_ops(&self, mut val: MutexGuard<i32>) { fn update_pending_ops(&self, mut val: MutexGuard<i32>, current_pid: Pid) {
debug_assert!(*val >= 0); debug_assert!(*val >= 0);
trace!("Updating pending ops, semaphore before: {:?}", *val); trace!("Updating pending ops, semaphore before: {:?}", *val);
@ -259,6 +253,7 @@ impl Semaphore {
// Step one: // Step one:
let mut value = *val; let mut value = *val;
let mut latest_modified_pid = current_pid;
if value > 0 { if value > 0 {
let mut pending_alters = self.pending_alters.lock(); let mut pending_alters = self.pending_alters.lock();
let mut cursor = pending_alters.cursor_front_mut(); let mut cursor = pending_alters.cursor_front_mut();
@ -282,8 +277,7 @@ impl Semaphore {
); );
value += i32::from(op.sem_buf.sem_op); value += i32::from(op.sem_buf.sem_op);
self.latest_modified_pid.store(op.pid, Ordering::Relaxed); latest_modified_pid = op.pid;
self.update_otime();
op.status.set_status(Status::Normal); op.status.set_status(Status::Normal);
op.waker.wake_up(); op.waker.wake_up();
cursor.remove_current().unwrap(); cursor.remove_current().unwrap();
@ -293,6 +287,12 @@ impl Semaphore {
} }
} }
if latest_modified_pid != 0 {
self.latest_modified_pid
.store(latest_modified_pid, Ordering::Relaxed);
self.update_otime();
}
// Step two: // Step two:
if value == 0 { if value == 0 {
let mut pending_const = self.pending_const.lock(); let mut pending_const = self.pending_const.lock();