latchref and nopref types

This commit is contained in:
Janis 2025-06-17 14:44:55 +02:00
parent 3458a900ee
commit 46504f64f2

View file

@ -163,6 +163,7 @@ pub mod task {
}
pub mod latch {
use core::marker::PhantomData;
use std::{
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
@ -283,6 +284,48 @@ pub mod latch {
}
}
pub struct LatchRef<'a, L: Latch> {
inner: *const L,
_marker: PhantomData<&'a L>,
}
impl<'a, L: Latch> LatchRef<'a, L> {
#[inline]
pub const fn new(latch: &'a L) -> Self {
Self {
inner: latch,
_marker: PhantomData,
}
}
}
impl<'a, L: Latch> Latch for LatchRef<'a, L> {
#[inline]
unsafe fn set_raw(this: *const Self) {
let this = &*this;
Latch::set_raw(this.inner);
}
}
impl<'a, L: Latch + Probe> Probe for LatchRef<'a, L> {
#[inline]
fn probe(&self) -> bool {
unsafe {
let this = &*self.inner;
Probe::probe(this)
}
}
}
pub struct NopLatch;
impl Latch for NopLatch {
#[inline]
unsafe fn set_raw(_this: *const Self) {
// do nothing
}
}
pub struct MutexLatch {
mutex: Mutex<bool>,
signal: Condvar,