From d62c77e6e0f661aad27ebd751cde2275cdc54107 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Jan 2021 16:43:26 +0800 Subject: [PATCH] libcortex_a9: fixed usage of deprecated APIs --- libcortex_a9/src/mutex.rs | 4 ++-- libcortex_a9/src/semaphore.rs | 4 ++-- libcortex_a9/src/uncached.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libcortex_a9/src/mutex.rs b/libcortex_a9/src/mutex.rs index b8eda33..de0d705 100644 --- a/libcortex_a9/src/mutex.rs +++ b/libcortex_a9/src/mutex.rs @@ -32,7 +32,7 @@ impl Mutex { /// Lock the Mutex, blocks when already locked pub fn lock(&self) -> MutexGuard { let mut irq = unsafe { enter_critical() }; - while self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED { + while self.locked.compare_exchange_weak(UNLOCKED, LOCKED, Ordering::AcqRel, Ordering::Relaxed).is_err() { unsafe { exit_critical(irq); spin_lock_yield(); @@ -44,7 +44,7 @@ impl Mutex { pub fn try_lock(&self) -> Option> { let irq = unsafe { enter_critical() }; - if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED { + if self.locked.compare_exchange_weak(UNLOCKED, LOCKED, Ordering::AcqRel, Ordering::Relaxed).is_err() { unsafe { exit_critical(irq) }; None } else { diff --git a/libcortex_a9/src/semaphore.rs b/libcortex_a9/src/semaphore.rs index a188499..36243e9 100644 --- a/libcortex_a9/src/semaphore.rs +++ b/libcortex_a9/src/semaphore.rs @@ -20,7 +20,7 @@ impl Semaphore { loop { let value = self.value.load(Ordering::Relaxed); if value > 0 { - if self.value.compare_and_swap(value, value - 1, Ordering::SeqCst) == value { + if self.value.compare_exchange_weak(value, value - 1, Ordering::SeqCst, Ordering::Relaxed).is_ok() { return Some(()); } } else { @@ -58,7 +58,7 @@ impl Semaphore { loop { let value = self.value.load(Ordering::Relaxed); if value < self.max { - if self.value.compare_and_swap(value, value + 1, Ordering::SeqCst) == value { + if self.value.compare_exchange_weak(value, value + 1, Ordering::SeqCst, Ordering::Relaxed).is_ok() { notify_spin_lock(); return; } diff --git a/libcortex_a9/src/uncached.rs b/libcortex_a9/src/uncached.rs index 8712e27..1ff962c 100644 --- a/libcortex_a9/src/uncached.rs +++ b/libcortex_a9/src/uncached.rs @@ -2,7 +2,7 @@ use core::{ ops::{Deref, DerefMut}, mem::{align_of, size_of}, }; -use alloc::alloc::{dealloc, Layout, LayoutErr}; +use alloc::alloc::{dealloc, Layout, LayoutError}; use crate::mmu::{L1_PAGE_SIZE, L1Table}; pub struct UncachedSlice { @@ -12,7 +12,7 @@ pub struct UncachedSlice { impl UncachedSlice { /// allocates in chunks of 1 MB - pub fn new T>(len: usize, default: F) -> Result { + pub fn new T>(len: usize, default: F) -> Result { // round to full pages let size = ((len * size_of::() - 1) | (L1_PAGE_SIZE - 1)) + 1; let align = align_of::()