From bb6f25d010dd9f227ab89fc03c1f913d407ed922 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 30 Dec 2020 01:06:05 +0100 Subject: [PATCH] Remove use of deprecated compare_and_swap. --- embassy-macros/src/lib.rs | 2 +- embassy/src/executor/mod.rs | 4 ++-- embassy/src/util/forever.rs | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 091e08cf..c2e2d9e2 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -150,7 +150,7 @@ pub fn interrupt_take(item: TokenStream) -> TokenStream { static TAKEN: ::core::sync::atomic::AtomicBool = ::core::sync::atomic::AtomicBool::new(false); - if TAKEN.compare_and_swap(false, true, ::core::sync::atomic::Ordering::AcqRel) { + if TAKEN.compare_exchange(false, true, ::core::sync::atomic::Ordering::AcqRel, ::core::sync::atomic::Ordering::Acquire).is_err() { panic!("IRQ Already taken"); } diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index 845d94c2..facd71d1 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs @@ -105,8 +105,8 @@ impl Task { if task .header .state - .compare_and_swap(0, state, Ordering::AcqRel) - == 0 + .compare_exchange(0, state, Ordering::AcqRel, Ordering::Acquire) + .is_ok() { // Initialize the task task.header.poll_fn.write(Self::poll); diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index 80dc0eda..b1bfd166 100644 --- a/embassy/src/util/forever.rs +++ b/embassy/src/util/forever.rs @@ -19,7 +19,11 @@ impl Forever { } pub fn put(&'static self, val: T) -> &'static mut T { - if self.used.compare_and_swap(false, true, Ordering::SeqCst) { + if self + .used + .compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire) + .is_ok() + { panic!("Forever.put() called multiple times"); }