From 45c39685b56a4dba1b71bdbbbe5f731c3c77dc50 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 13 Sep 2024 12:47:37 +0200 Subject: [PATCH] Use portable-atomic This should not have run-time impact on platforms that support atomic boolean compare-and-swap, but enables its use on microcontrollers where the user configures portable-atomic in such a way that atomics can be emulated (eg. through disabling interrupts). --- Cargo.toml | 1 + src/lib.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9fe3c62..3395074 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ documentation = "https://docs.rs/try-lock" readme = "README.md" [dependencies] +portable-atomic = { version = "1.3.0", default-features = false, features = ["require-cas"] } diff --git a/src/lib.rs b/src/lib.rs index 2811996..7186d44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,10 +46,13 @@ #[cfg(test)] extern crate core; +extern crate portable_atomic; + use core::cell::UnsafeCell; use core::fmt; use core::ops::{Deref, DerefMut}; -use core::sync::atomic::{AtomicBool, Ordering}; +use portable_atomic::AtomicBool; +use core::sync::atomic::Ordering; use core::marker::PhantomData; /// A light-weight lock guarded by an atomic boolean.