#[derive(Debug, Clone, Copy, Eq, PartialEq)]
enum FastCasSuccessKind {
Updated,
Finished,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct FastCasSuccess<R> {
previous: usize,
current: usize,
output: R,
attempts: u32,
kind: FastCasSuccessKind,
}
impl<R> FastCasSuccess<R> {
#[inline]
pub(crate) const fn updated(previous: usize, current: usize, output: R, attempts: u32) -> Self {
Self {
previous,
current,
output,
attempts,
kind: FastCasSuccessKind::Updated,
}
}
#[inline]
pub(crate) const fn finished(current: usize, output: R, attempts: u32) -> Self {
Self {
previous: current,
current,
output,
attempts,
kind: FastCasSuccessKind::Finished,
}
}
#[inline]
pub const fn previous(&self) -> usize {
self.previous
}
#[inline]
pub const fn current(&self) -> usize {
self.current
}
#[inline]
pub const fn output(&self) -> &R {
&self.output
}
#[inline]
pub fn into_output(self) -> R {
self.output
}
#[inline]
pub const fn attempts(&self) -> u32 {
self.attempts
}
#[inline]
pub const fn is_updated(&self) -> bool {
matches!(self.kind, FastCasSuccessKind::Updated)
}
#[inline]
pub const fn is_finished(&self) -> bool {
matches!(self.kind, FastCasSuccessKind::Finished)
}
}