cacheline aligned heartbeat atomics

This commit is contained in:
Janis 2025-02-20 21:51:16 +01:00
parent af8103b843
commit 4f9c5c00bb

View file

@ -752,6 +752,7 @@ use std::{
time::Duration,
};
use crossbeam::utils::CachePadded;
use job::*;
use parking_lot::{Condvar, Mutex};
use util::DropGuard;
@ -760,7 +761,7 @@ pub struct Scope {
join_count: Cell<usize>,
context: Arc<Context>,
index: usize,
heartbeat: Arc<AtomicBool>,
heartbeat: Arc<CachePadded<AtomicBool>>,
queue: UnsafeCell<JobList>,
}
@ -1058,7 +1059,7 @@ struct Context {
struct SharedContext {
jobs: BTreeMap<usize, NonNull<Job>>,
heartbeats: BTreeMap<usize, Weak<AtomicBool>>,
heartbeats: BTreeMap<usize, Weak<CachePadded<AtomicBool>>>,
// monotonic increasing id
heartbeats_id: usize,
should_stop: bool,
@ -1067,11 +1068,11 @@ struct SharedContext {
unsafe impl Send for SharedContext {}
impl SharedContext {
fn new_heartbeat(&mut self) -> (Arc<AtomicBool>, usize) {
fn new_heartbeat(&mut self) -> (Arc<CachePadded<AtomicBool>>, usize) {
let index = self.heartbeats_id;
self.heartbeats_id.checked_add(1).unwrap();
let is_set = Arc::new(AtomicBool::new(false));
let is_set = Arc::new(CachePadded::new(AtomicBool::new(false)));
let weak = Arc::downgrade(&is_set);
self.heartbeats.insert(index, weak);