1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

Change lock to try_lock to better align with Rust's verbiage

This commit is contained in:
Stephen Marz 2020-04-27 09:46:59 -04:00
parent d49ea6e040
commit 30fcd7894a

View File

@ -26,7 +26,8 @@ impl<'a> Mutex {
&self.state
}
pub fn lock(&mut self) -> bool {
/// Try to lock the Mutex. If the mutex is already locked, this function returns false, otherwise it will return true if the mutex was acquired.
pub fn try_lock(&mut self) -> bool {
unsafe {
let state: MutexState;
llvm_asm!("amoswap.w.aq $0, $1, ($2)\n" : "=r"(state) : "r"(1), "r"(self) :: "volatile");
@ -42,16 +43,17 @@ impl<'a> Mutex {
/// Never use a sleep lock for the process list. Sleeping requires
/// the process list to function, so you'll deadlock if you do.
pub fn sleep_lock(&mut self) {
while !self.lock() {
while !self.try_lock() {
syscall_sleep(DEFAULT_LOCK_SLEEP);
}
}
/// Can safely be used inside of an interrupt context.
pub fn spin_lock(&mut self) {
while !self.lock() {}
while !self.try_lock() {}
}
/// Unlock a mutex without regard for its previous state.
pub fn unlock(&mut self) {
unsafe {
llvm_asm!("amoswap.w.rl zero, zero, ($0)" :: "r"(self) :: "volatile");