commit
ae5ad91bbb
@ -35,7 +35,7 @@ use crate::waitqueue::WakerRegistration;
|
|||||||
/// The channel requires a buffer of recyclable elements. Writing to the channel is done through
|
/// The channel requires a buffer of recyclable elements. Writing to the channel is done through
|
||||||
/// an `&mut T`.
|
/// an `&mut T`.
|
||||||
pub struct Channel<'a, M: RawMutex, T> {
|
pub struct Channel<'a, M: RawMutex, T> {
|
||||||
buf: *mut T,
|
buf: BufferPtr<T>,
|
||||||
phantom: PhantomData<&'a mut T>,
|
phantom: PhantomData<&'a mut T>,
|
||||||
state: Mutex<M, RefCell<State>>,
|
state: Mutex<M, RefCell<State>>,
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
|
|||||||
assert!(len != 0);
|
assert!(len != 0);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
buf: buf.as_mut_ptr(),
|
buf: BufferPtr(buf.as_mut_ptr()),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
state: Mutex::new(RefCell::new(State {
|
state: Mutex::new(RefCell::new(State {
|
||||||
capacity: len,
|
capacity: len,
|
||||||
@ -94,6 +94,18 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
struct BufferPtr<T>(*mut T);
|
||||||
|
|
||||||
|
impl<T> BufferPtr<T> {
|
||||||
|
unsafe fn add(&self, count: usize) -> *mut T {
|
||||||
|
self.0.add(count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<T> Send for BufferPtr<T> {}
|
||||||
|
unsafe impl<T> Sync for BufferPtr<T> {}
|
||||||
|
|
||||||
/// Send-only access to a [`Channel`].
|
/// Send-only access to a [`Channel`].
|
||||||
pub struct Sender<'a, M: RawMutex, T> {
|
pub struct Sender<'a, M: RawMutex, T> {
|
||||||
channel: &'a Channel<'a, M, T>,
|
channel: &'a Channel<'a, M, T>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user