Skip to content

Commit 1eb6446

Browse files
committed
Use core atomic types instead of intrinsics on non-MSP430 targets
1 parent f3e0972 commit 1eb6446

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
//! ```
6969
7070
#![no_std]
71-
#![feature(asm_experimental_arch)]
72-
#![cfg_attr(not(target_arch = "msp430"), feature(core_intrinsics))]
71+
#![cfg_attr(target_arch = "msp430", feature(asm_experimental_arch))]
7372

73+
#[cfg(target_arch = "msp430")]
7474
use core::arch::asm;
7575
use core::cell::UnsafeCell;
7676
use core::fmt;
@@ -681,42 +681,50 @@ macro_rules! atomic_int {
681681
impl AtomicOperations for $int_type {
682682
#[inline(always)]
683683
unsafe fn atomic_store(dst: *mut Self, val: Self) {
684-
::core::intrinsics::atomic_store(dst, val);
684+
(*(dst as *const ::core::sync::atomic::$atomic_type))
685+
.store(val, ::core::sync::atomic::Ordering::SeqCst);
685686
}
686687

687688
#[inline(always)]
688689
unsafe fn atomic_load(dst: *const Self) -> Self {
689-
::core::intrinsics::atomic_load(dst)
690+
(*(dst as *const ::core::sync::atomic::$atomic_type))
691+
.load(::core::sync::atomic::Ordering::SeqCst)
690692
}
691693

692694
#[inline(always)]
693695
unsafe fn atomic_add(dst: *mut Self, val: Self) {
694-
::core::intrinsics::atomic_xadd(dst, val);
696+
(*(dst as *const ::core::sync::atomic::$atomic_type))
697+
.fetch_add(val, ::core::sync::atomic::Ordering::SeqCst);
695698
}
696699

697700
#[inline(always)]
698701
unsafe fn atomic_sub(dst: *mut Self, val: Self) {
699-
::core::intrinsics::atomic_xsub(dst, val);
702+
(*(dst as *const ::core::sync::atomic::$atomic_type))
703+
.fetch_sub(val, ::core::sync::atomic::Ordering::SeqCst);
700704
}
701705

702706
#[inline(always)]
703707
unsafe fn atomic_and(dst: *mut Self, val: Self) {
704-
::core::intrinsics::atomic_and(dst, val);
708+
(*(dst as *const ::core::sync::atomic::$atomic_type))
709+
.fetch_and(val, ::core::sync::atomic::Ordering::SeqCst);
705710
}
706711

707712
#[inline(always)]
708713
unsafe fn atomic_clear(dst: *mut Self, val: Self) {
709-
::core::intrinsics::atomic_and(dst, !val);
714+
(*(dst as *const ::core::sync::atomic::$atomic_type))
715+
.fetch_and(!val, ::core::sync::atomic::Ordering::SeqCst);
710716
}
711717

712718
#[inline(always)]
713719
unsafe fn atomic_or(dst: *mut Self, val: Self) {
714-
::core::intrinsics::atomic_or(dst, val);
720+
(*(dst as *const ::core::sync::atomic::$atomic_type))
721+
.fetch_or(val, ::core::sync::atomic::Ordering::SeqCst);
715722
}
716723

717724
#[inline(always)]
718725
unsafe fn atomic_xor(dst: *mut Self, val: Self) {
719-
::core::intrinsics::atomic_xor(dst, val);
726+
(*(dst as *const ::core::sync::atomic::$atomic_type))
727+
.fetch_xor(val, ::core::sync::atomic::Ordering::SeqCst);
720728
}
721729
}
722730
}

0 commit comments

Comments
 (0)