Skip to content

Commit a5512a9

Browse files
committed
Use core atomic types instead of intrinsics on non-MSP430 targets
1 parent 2c54a1c commit a5512a9

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;
@@ -676,42 +676,50 @@ macro_rules! atomic_int {
676676
impl AtomicOperations for $int_type {
677677
#[inline(always)]
678678
unsafe fn atomic_store(dst: *mut Self, val: Self) {
679-
::core::intrinsics::atomic_store(dst, val);
679+
(*(dst as *const ::core::sync::atomic::$atomic_type))
680+
.store(val, ::core::sync::atomic::Ordering::SeqCst);
680681
}
681682

682683
#[inline(always)]
683684
unsafe fn atomic_load(dst: *const Self) -> Self {
684-
::core::intrinsics::atomic_load(dst)
685+
(*(dst as *const ::core::sync::atomic::$atomic_type))
686+
.load(::core::sync::atomic::Ordering::SeqCst)
685687
}
686688

687689
#[inline(always)]
688690
unsafe fn atomic_add(dst: *mut Self, val: Self) {
689-
::core::intrinsics::atomic_xadd(dst, val);
691+
(*(dst as *const ::core::sync::atomic::$atomic_type))
692+
.fetch_add(val, ::core::sync::atomic::Ordering::SeqCst);
690693
}
691694

692695
#[inline(always)]
693696
unsafe fn atomic_sub(dst: *mut Self, val: Self) {
694-
::core::intrinsics::atomic_xsub(dst, val);
697+
(*(dst as *const ::core::sync::atomic::$atomic_type))
698+
.fetch_sub(val, ::core::sync::atomic::Ordering::SeqCst);
695699
}
696700

697701
#[inline(always)]
698702
unsafe fn atomic_and(dst: *mut Self, val: Self) {
699-
::core::intrinsics::atomic_and(dst, val);
703+
(*(dst as *const ::core::sync::atomic::$atomic_type))
704+
.fetch_and(val, ::core::sync::atomic::Ordering::SeqCst);
700705
}
701706

702707
#[inline(always)]
703708
unsafe fn atomic_clear(dst: *mut Self, val: Self) {
704-
::core::intrinsics::atomic_and(dst, !val);
709+
(*(dst as *const ::core::sync::atomic::$atomic_type))
710+
.fetch_and(!val, ::core::sync::atomic::Ordering::SeqCst);
705711
}
706712

707713
#[inline(always)]
708714
unsafe fn atomic_or(dst: *mut Self, val: Self) {
709-
::core::intrinsics::atomic_or(dst, val);
715+
(*(dst as *const ::core::sync::atomic::$atomic_type))
716+
.fetch_or(val, ::core::sync::atomic::Ordering::SeqCst);
710717
}
711718

712719
#[inline(always)]
713720
unsafe fn atomic_xor(dst: *mut Self, val: Self) {
714-
::core::intrinsics::atomic_xor(dst, val);
721+
(*(dst as *const ::core::sync::atomic::$atomic_type))
722+
.fetch_xor(val, ::core::sync::atomic::Ordering::SeqCst);
715723
}
716724
}
717725
}

0 commit comments

Comments
 (0)