Skip to content
Snippets Groups Projects
Commit 731e8ae1 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

rewrite the test for less unsafety

parent 5ff961c3
Branches
No related tags found
No related merge requests found
#![deny(warnings)]
extern crate heapless; extern crate heapless;
use std::thread; use std::thread;
...@@ -8,14 +10,20 @@ use heapless::RingBuffer; ...@@ -8,14 +10,20 @@ use heapless::RingBuffer;
fn once() { fn once() {
static mut RB: RingBuffer<i32, [i32; 4]> = RingBuffer::new(); static mut RB: RingBuffer<i32, [i32; 4]> = RingBuffer::new();
unsafe { RB.split() }.0.enqueue(0).unwrap(); let rb = unsafe { &mut RB };
rb.enqueue(0).unwrap();
let (mut p, mut c) = rb.split();
thread::spawn(|| { p.enqueue(1).unwrap();
unsafe { RB.split() }.0.enqueue(1).unwrap();
thread::spawn(move || {
p.enqueue(1).unwrap();
}); });
thread::spawn(|| { thread::spawn(move || {
unsafe { RB.split() }.1.dequeue().unwrap(); c.dequeue().unwrap();
}); });
} }
...@@ -23,16 +31,20 @@ fn once() { ...@@ -23,16 +31,20 @@ fn once() {
fn twice() { fn twice() {
static mut RB: RingBuffer<i32, [i32; 8]> = RingBuffer::new(); static mut RB: RingBuffer<i32, [i32; 8]> = RingBuffer::new();
unsafe { RB.split() }.0.enqueue(0).unwrap(); let rb = unsafe { &mut RB };
unsafe { RB.split() }.0.enqueue(1).unwrap();
rb.enqueue(0).unwrap();
rb.enqueue(1).unwrap();
let (mut p, mut c) = rb.split();
thread::spawn(|| { thread::spawn(move || {
unsafe { RB.split() }.0.enqueue(2).unwrap(); p.enqueue(2).unwrap();
unsafe { RB.split() }.0.enqueue(3).unwrap(); p.enqueue(3).unwrap();
}); });
thread::spawn(|| { thread::spawn(move || {
unsafe { RB.split() }.1.dequeue().unwrap(); c.dequeue().unwrap();
unsafe { RB.split() }.1.dequeue().unwrap(); c.dequeue().unwrap();
}); });
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment