latchref and nopref types
This commit is contained in:
parent
3458a900ee
commit
46504f64f2
43
src/lib.rs
43
src/lib.rs
|
@ -163,6 +163,7 @@ pub mod task {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod latch {
|
pub mod latch {
|
||||||
|
use core::marker::PhantomData;
|
||||||
use std::{
|
use std::{
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
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 {
|
pub struct MutexLatch {
|
||||||
mutex: Mutex<bool>,
|
mutex: Mutex<bool>,
|
||||||
signal: Condvar,
|
signal: Condvar,
|
||||||
|
|
Loading…
Reference in a new issue