Skip to content

Commit

Permalink
fix(partition): use safer atomic orderings
Browse files Browse the repository at this point in the history
Replace `Ordering::Relaxed` with `Ordering::SeqCst` as a relaxed ordering may have unexpected behaviour. Also, the performance hit should not be significant.
  • Loading branch information
florianhartung authored and sevenautumns committed Feb 27, 2024
1 parent fc19383 commit c318df6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions partition/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ impl Process {

pub(crate) fn get_self() -> Option<Arc<Self>> {
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());
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c318df6

Please sign in to comment.