aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-sync/src/zerocopy_channel.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/embassy-sync/src/zerocopy_channel.rs b/embassy-sync/src/zerocopy_channel.rs
index 15914578e..ad6fe74c5 100644
--- a/embassy-sync/src/zerocopy_channel.rs
+++ b/embassy-sync/src/zerocopy_channel.rs
@@ -35,7 +35,7 @@ use crate::waitqueue::WakerRegistration;
35/// The channel requires a buffer of recyclable elements. Writing to the channel is done through 35/// The channel requires a buffer of recyclable elements. Writing to the channel is done through
36/// an `&mut T`. 36/// an `&mut T`.
37pub struct Channel<'a, M: RawMutex, T> { 37pub struct Channel<'a, M: RawMutex, T> {
38 buf: *mut T, 38 buf: BufferPtr<T>,
39 phantom: PhantomData<&'a mut T>, 39 phantom: PhantomData<&'a mut T>,
40 state: Mutex<M, RefCell<State>>, 40 state: Mutex<M, RefCell<State>>,
41} 41}
@@ -50,7 +50,7 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
50 assert!(len != 0); 50 assert!(len != 0);
51 51
52 Self { 52 Self {
53 buf: buf.as_mut_ptr(), 53 buf: BufferPtr(buf.as_mut_ptr()),
54 phantom: PhantomData, 54 phantom: PhantomData,
55 state: Mutex::new(RefCell::new(State { 55 state: Mutex::new(RefCell::new(State {
56 capacity: len, 56 capacity: len,
@@ -94,6 +94,18 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
94 } 94 }
95} 95}
96 96
97#[repr(transparent)]
98struct BufferPtr<T>(*mut T);
99
100impl<T> BufferPtr<T> {
101 unsafe fn add(&self, count: usize) -> *mut T {
102 self.0.add(count)
103 }
104}
105
106unsafe impl<T> Send for BufferPtr<T> {}
107unsafe impl<T> Sync for BufferPtr<T> {}
108
97/// Send-only access to a [`Channel`]. 109/// Send-only access to a [`Channel`].
98pub struct Sender<'a, M: RawMutex, T> { 110pub struct Sender<'a, M: RawMutex, T> {
99 channel: &'a Channel<'a, M, T>, 111 channel: &'a Channel<'a, M, T>,