Created
May 10, 2020 03:54
-
-
Save Abdillah/17d48586c7b49371199466ea67bf936a to your computer and use it in GitHub Desktop.
Implementation of sync_val_compare_and_swap in ESP8266 (it is very general for embedded actually).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/bif_gcc_atomic_val_comp_swap.html | |
#[cfg(not(feature = "disable-fake-atomics"))] | |
#[no_mangle] | |
fn __sync_val_compare_and_swap_1(ptr_exch: *mut u8, cmp: u8, exch: u8) -> u8 { | |
let oldval = unsafe { *ptr_exch }; | |
if cmp == oldval { | |
unsafe { core::ptr::write(ptr_exch, cmp) }; | |
} | |
oldval | |
} | |
#[cfg(not(feature = "disable-fake-atomics"))] | |
#[no_mangle] | |
fn __sync_val_compare_and_swap_2(ptr_exch: *mut u16, cmp: u16, exch: u16) -> u16 { | |
let oldval = unsafe { *ptr_exch }; | |
if cmp == oldval { | |
unsafe { core::ptr::write(ptr_exch, cmp) }; | |
} | |
oldval | |
} | |
#[cfg(not(feature = "disable-fake-atomics"))] | |
#[no_mangle] | |
fn __sync_val_compare_and_swap_4(ptr_exch: *mut u32, cmp: u32, exch: u32) -> u32 { | |
let oldval = unsafe { *ptr_exch }; | |
if cmp == oldval { | |
unsafe { core::ptr::write(ptr_exch, cmp) }; | |
} | |
oldval | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment