From 46504f64f24e265688ba21100a7e317c91416a50 Mon Sep 17 00:00:00 2001 From: Janis Date: Tue, 17 Jun 2025 14:44:55 +0200 Subject: [PATCH] latchref and nopref types --- src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5bea4f0..f609657 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, signal: Condvar,