m68k problem and libstdc++

Roman Zippel zippel@linux-m68k.org
Fri Jan 4 19:31:00 GMT 2002


Hi,

Peter Barada wrote:

> >(I know the architecture fairly well, at least I used to, but I'm
> >not expert on multiprocessor synchronization.)

It's not only for multiprocessor systems (which are quite nonexistent
for m68k AFAIK), but also for multithreading. cas is used for an
undivisible exchange operation, which is neither interrupted by another
cpu nor by another thread.

> Since the straight 68k and 5x0x don't support CAS, you could:
> 
> #if defined(__mc68000__) || defined(__mcf5200__)
> static inline _Atomic_word
> __attribute__ ((__unused__))
> __exchange_and_add (volatile _Atomic_word *__mem, int __val)
> {
>   register _Atomic_word __result = *__mem;
>   register _Atomic_word __temp;
>   __asm__ __volatile__ ("1: move%.l %0,%1;"
>                         "   add%.l %2,%1;"
>                         "   cmp%.l %0,%3;"
>                         "   jbeq 2f;"
>                         "   move%.l %3,%0;"
>                         "   jra 1b;"
>                         "2: move%.l %1,%3"
>                         : "=d" (__result), "=&d" (__temp)
>                         : "d" (__val), "m" (*__mem), "0" (__result)
>                         : "memory");
>   return __result;

This isn't threadsafe, so "__result = *__mem; *__mem += __val;" would do
the same job.

bye, Roman



More information about the Libstdc++ mailing list