From 1f4add397b3d6774ea4a685b5b4e7de6ca911f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Stein?= Date: Fri, 30 Aug 2019 15:56:42 +0800 Subject: [PATCH] mailbox: fix race condition --- src/mailbox.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mailbox.rs b/src/mailbox.rs index 1459a2db..a258f292 100644 --- a/src/mailbox.rs +++ b/src/mailbox.rs @@ -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 }