Skip to content

Commit ae5ad91

Browse files
authored
Merge pull request #3829 from lsartory/fix_3828
Fix issue #3828
2 parents a2791ae + 7d66f1c commit ae5ad91

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

embassy-sync/src/zerocopy_channel.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::waitqueue::WakerRegistration;
3535
/// The channel requires a buffer of recyclable elements. Writing to the channel is done through
3636
/// an `&mut T`.
3737
pub struct Channel<'a, M: RawMutex, T> {
38-
buf: *mut T,
38+
buf: BufferPtr<T>,
3939
phantom: PhantomData<&'a mut T>,
4040
state: Mutex<M, RefCell<State>>,
4141
}
@@ -50,7 +50,7 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
5050
assert!(len != 0);
5151

5252
Self {
53-
buf: buf.as_mut_ptr(),
53+
buf: BufferPtr(buf.as_mut_ptr()),
5454
phantom: PhantomData,
5555
state: Mutex::new(RefCell::new(State {
5656
capacity: len,
@@ -94,6 +94,18 @@ impl<'a, M: RawMutex, T> Channel<'a, M, T> {
9494
}
9595
}
9696

97+
#[repr(transparent)]
98+
struct BufferPtr<T>(*mut T);
99+
100+
impl<T> BufferPtr<T> {
101+
unsafe fn add(&self, count: usize) -> *mut T {
102+
self.0.add(count)
103+
}
104+
}
105+
106+
unsafe impl<T> Send for BufferPtr<T> {}
107+
unsafe impl<T> Sync for BufferPtr<T> {}
108+
97109
/// Send-only access to a [`Channel`].
98110
pub struct Sender<'a, M: RawMutex, T> {
99111
channel: &'a Channel<'a, M, T>,

0 commit comments

Comments
 (0)