From c318df6f1b66e44348cbc98608e350bb7fec4bfe Mon Sep 17 00:00:00 2001 From: Florian Hartung Date: Thu, 22 Feb 2024 11:26:02 +0100 Subject: [PATCH] fix(partition): use safer atomic orderings Replace `Ordering::Relaxed` with `Ordering::SeqCst` as a relaxed ordering may have unexpected behaviour. Also, the performance hit should not be significant. --- partition/src/process.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/partition/src/process.rs b/partition/src/process.rs index d4ca83e..a4c5ab1 100644 --- a/partition/src/process.rs +++ b/partition/src/process.rs @@ -68,14 +68,14 @@ impl Process { pub(crate) fn get_self() -> Option> { if let Some(p) = APERIODIC_PROCESS.get() { - let id = p.pid.load(std::sync::atomic::Ordering::Relaxed); + let id = p.pid.load(Ordering::SeqCst); if id == nix::unistd::gettid().as_raw() { return Some(p.clone()); } } if let Some(p) = PERIODIC_PROCESS.get() { - let id = p.pid.load(std::sync::atomic::Ordering::Relaxed); + let id = p.pid.load(Ordering::SeqCst); if id == nix::unistd::gettid().as_raw() { return Some(p.clone()); } @@ -126,7 +126,7 @@ impl Process { .lev_typ(SystemError::Panic, ErrorLevel::Partition)?; // Receive thread id and store it let pid_raw = pid_rx.recv().unwrap(); - self.pid.store(pid_raw, Ordering::Relaxed); + self.pid.store(pid_raw, Ordering::SeqCst); let pid = Pid::from_raw(pid_raw); // Freeze thread by moving it to the cgroup cg.mv_thread(pid).unwrap();