Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created October 15, 2012 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/3895575 to your computer and use it in GitHub Desktop.
Save piscisaureus/3895575 to your computer and use it in GitHub Desktop.
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