mailbox: fix race condition

multiprocessing
Björn Stein 2019-08-30 15:56:42 +08:00 committed by Sebastien Bourdeauducq
parent 60bab77a19
commit 1f4add397b
1 changed files with 5 additions and 4 deletions

View File

@ -58,15 +58,16 @@ impl OneWayMailbox {
write_volatile(&mut self.pointer, 0);
write_volatile(&mut self.echo, 0);
}
asm::dmb();
}
// send a pointer from one core to be received by the other core
pub fn send(&mut self, ptr: usize) -> usize {
assert!(ptr != 0); // ptr may not be the NULL-like flag
asm::dmb(); // ensure data at (ptr) has been fully written
unsafe {
write_volatile(&mut self.pointer, ptr);
}
asm::dmb(); // ensure data at (ptr) has been fully written
ptr
}
@ -82,13 +83,13 @@ impl OneWayMailbox {
ptr
}
// return true if and only if the next self.receive() will return
// actual data rather than 0
// return true if it is guaranteed that the next self.receive()
// will return actual data rather than 0
pub fn available(&self) -> bool {
let ptr = unsafe {
asm::dmb();
read_volatile(&self.pointer)
};
asm::dmb();
ptr != 0
}