This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fw: [patch] Make std::tr1::shared_ptr thread-safe.
On Fri, Apr 01, 2005 at 05:19:48PM +0200, Paolo Carlini wrote:
> or powerpc:
>
> _Atomic_word
> __attribute__ ((__unused__))
> __exchange_and_add(volatile _Atomic_word* __mem, int __val)
> {
> _Atomic_word __tmp, __res;
> __asm__ __volatile__ (
> "/* Inline exchange & add */\n"
> "0:\t"
> "lwarx %0,0,%3 \n\t"
> "add%I4 %1,%0,%4 \n\t"
> _STWCX " %1,0,%3 \n\t"
> "bne- 0b \n\t"
> "/* End exchange & add */"
> : "=&b"(__res), "=&r"(__tmp), "=m" (*__mem)
> : "r" (__mem), "Ir"(__val), "m" (*__mem)
> : "cr0");
> return __res;
> }
>
> void
> __attribute__ ((__unused__))
> __atomic_add(volatile _Atomic_word* __mem, int __val)
> {
> _Atomic_word __tmp;
> __asm__ __volatile__ (
> "/* Inline atomic add */\n"
> "0:\t"
> "lwarx %0,0,%2 \n\t"
> "add%I3 %0,%0,%3 \n\t"
> _STWCX " %0,0,%2 \n\t"
> "bne- 0b \n\t"
> "/* End atomic add */"
> : "=&b"(__tmp), "=m" (*__mem)
> : "r" (__mem), "Ir"(__val), "m" (*__mem)
> : "cr0");
> }
where _STWCX is defined as:
#ifdef __PPC405__
#define _STWCX "sync \n\tstwcx. "
#else
#define _STWCX "stwcx. "
#endif