RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

msba2: implement __sync_bool_compare_and_swap

Open mehlis opened this issue 13 years ago • 5 comments

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?

mehlis avatar Nov 26 '13 21:11 mehlis

Not at all.

OlegHahm avatar Nov 27 '13 17:11 OlegHahm

maybe I can help, what's the problem?

kaspar030 avatar Nov 27 '13 17:11 kaspar030

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

mehlis avatar Nov 27 '13 18:11 mehlis

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;
}

thomaseichinger avatar Nov 28 '13 12:11 thomaseichinger

this feature request was driven by the pthread layer. I removed this dependency in pthread, so I'll close this.

mehlis avatar Jan 20 '14 19:01 mehlis