[riot-notifications] [RIOT] msba2: implement __sync_bool_compare_and_swap (#387)

Thomas Eichinger notifications at github.com
Thu Nov 28 13:07:44 CET 2013


What was your problem with porting the above code?
The ```LDREX``` and ```STREX``` statements?

For ARMv5 and earlier and types <= 32 bit the following should work
``` C
bool operator()( T *ptr, U oldval, U newval ) const
{
  register int result = 1;
  asm volatile (
    "ldr     r0, [%1]\n\t"    /* load current val into r0*/
    "cmp     r0, %2 \n\t"     /* compare with oldval */
    "streq   %3, [%1]\n\t"    /* store newval if eq */
    "eoreq   %0, %0\n\t"      /* set result 0 if updated */
    : "=&r" (result)
    : "r"(ptr), "r"(oldval), "r"(newval)
  );
  return result == 0;
}
```

---
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/387#issuecomment-29459381
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20131128/24942a09/attachment.html>


More information about the notifications mailing list