use std::sync::{
Arc,
atomic::{AtomicU64, Ordering},
};
#[derive(Default)]
pub(in crate::engine) struct PayloadWrites {
bytes: AtomicU64,
parent: Option<Arc<PayloadWrites>>,
}
impl PayloadWrites {
pub(in crate::engine) fn child(parent: Arc<Self>) -> Self {
Self {
parent: Some(parent),
..Self::default()
}
}
pub(in crate::engine) fn add(&self, bytes: usize) {
self.bytes.fetch_add(bytes as u64, Ordering::Relaxed);
if let Some(parent) = &self.parent {
parent.add(bytes);
}
}
pub(in crate::engine) fn snapshot(&self) -> u64 {
self.bytes.load(Ordering::Relaxed)
}
}