Skip to content

Commit

Permalink
add overaligned_zst tests
Browse files Browse the repository at this point in the history
  • Loading branch information
QuarticCat authored Sep 20, 2023
1 parent 0d3a3e1 commit 2dc6a1e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use std::{
/// holds pointer to that data in another side stack, and copies memory from
/// that pointer location
/// 2. When data size T is equal or less than pointer size:
/// serialize data itself in pointer address, with this action KanalPtr
/// serialize data itself in pointer address, with this action KanalPtr
/// removes one unnecessary memory load operation and improves speed. This
/// structure is unsafe. KanalPtr should be pinned to memory location or be a
/// member of pinned structure to work correctly.
/// member of pinned structure to work correctly. In particular, ZSTs should be
/// treated carefully as their alignments can be larger than the alignment of
/// pointers.
pub(crate) struct KanalPtr<T>(UnsafeCell<MaybeUninit<*mut T>>);

impl<T> Default for KanalPtr<T> {
Expand Down
18 changes: 18 additions & 0 deletions tests/async_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,22 @@ mod asyncs {
assert_eq!(r.recv().await.unwrap(), 0);
assert_eq!(r.recv().await.unwrap(), 1);
}

#[tokio::test]
async fn spsc_overaligned_zst() {
#[repr(align(1024))]
struct Foo;

let (tx, rx) = new(Some(0));

tokio::spawn(async move {
for _i in 0..MESSAGES {
tx.send(Foo).await.unwrap();
}
});

for _ in 0..MESSAGES {
rx.recv().await.unwrap();
}
}
}
21 changes: 21 additions & 0 deletions tests/sync_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ fn spsc_delayed_send() {
.unwrap();
}

#[test]
fn spsc_overaligned_zst() {
#[repr(align(1024))]
struct Foo;

let (tx, rx) = new(0.into());
crossbeam::scope(|scope| {
scope.spawn(|_| {
for _i in 0..10 {
delay();
tx.send(Foo).unwrap();
}
});

for _ in 0..10 {
rx.recv().unwrap();
}
})
.unwrap();
}

#[test]
fn integrity_u8() {
integrity_test!(0u8, !0u8);
Expand Down

0 comments on commit 2dc6a1e

Please sign in to comment.