msba2: implement __sync_bool_compare_and_swap
for an easy, slim and fast posix layer of threads (https://github.com/RIOT-OS/RIOT/pull/219) the function:
__sync_bool_compare_and_swap
is required on the msba2.
I was not able to port the function from here: http://armv6-atomic.googlecode.com/files/armv6_atomic.h
@OlegHahm are you an ARM assembly expert?
Not at all.
maybe I can help, what's the problem?
I want to use "this" function in the pthread layer. The reason to use this function is easy: I don't want to disable interrupts...
I think this (cmp and swap) functionality is useful in many cases...
An example: https://github.com/RIOT-OS/RIOT/pull/219/files#diff-29a28c28f10f53c479ddab0e6beb42bcR58
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
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;
}
this feature request was driven by the pthread layer. I removed this dependency in pthread, so I'll close this.