mailbox: fix race condition

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