libstdc++-v3/config/cpu/m68k/atomicity.h

Jonathan Wakely jwakely@redhat.com
Fri Sep 9 13:14:00 GMT 2016


On 09/09/16 10:28 +0200, Sebastian Huber wrote:
>Hello,
>
>for RTEMS there is a special case in:
>
>libstdc++-v3/config/cpu/m68k/atomicity.h
>
>[...]
>namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
>{
>[...]
>#elif defined(__rtems__)
>  // TAS/JBNE is unsafe on systems with strict priority-based scheduling.
>  // Disable interrupts, which we can do only from supervisor mode.
>  _Atomic_word
>  __attribute__ ((__unused__))
>  __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
>  {
>    _Atomic_word __result;
>    short __level, __tmpsr;
>    __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w 
>%1,%%sr"
>              : "=d"(__level), "=d"(__tmpsr) : "1"(0x700));
>
>    __result = *__mem;
>    *__mem = __result + __val;
>    __asm__ __volatile__ ("move%.w %0,%%sr" : : "d"(__level));
>
>    return __result;
>  }
>
>#else
>[...]
>
>Since C++14 is the default for GCC 6, would it be possible to use the 
>standard atomic operations instead? For targets that don't support the 
>operations in hardware, this would lead to a libatomic dependency.

C++14 isn't relevant, since the std::atomic_* operations only work on
std::atomic<T> objects, not _Atomic_word objects.

The code could use the same __atomic_* built-ins that are used by
std::atomic<T>, but they are always available, so C++14 isn't needed
for that.

As you say, that introduces a dependency on libatomic, so would be a
decision for the target maintainer to make.



More information about the Libstdc++ mailing list