Created
October 15, 2012 21:20
-
-
Save piscisaureus/3895575 to your computer and use it in GitHub Desktop.
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
void* sync_fetch_and_set_ptr(void* volatile* target, void* new_value) | |
{ | |
void* previous_value; | |
int retry; | |
__asm__ volatile( | |
"1: ldrex %0, [%1];" | |
" strex %3, %2, [%1];" | |
" teq %3, #0;" | |
" bne 1b;" | |
:"=r"(previous_value) | |
:"+r"(target), "r"(new_value), "=&r"(retry) | |
:"cc", "memory" | |
); | |
return previous_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment