Fw: [patch] Make std::tr1::shared_ptr thread-safe.
Paolo Carlini
pcarlini@suse.de
Fri Apr 1 15:19:00 GMT 2005
Hi Alexander,
>That's certainly not impossible, I suppose. Where is it documented? Is it
>subject to change at any time without notice?
>
>
I'm afraid we don't have documentation for this: all is under the
responsability of the port maintainer... I can be wrong, sure, but I'm
afraid this is the current state of affairs.
>>Maybe you can volunteer to check a few of those implementations? Maybe
>>ia64? For your convenience, reads, simply (exploiting built-ins in such
>>case):
>>
>>namespace __gnu_cxx
>>{
>> _Atomic_word
>> __attribute__ ((__unused__))
>> __exchange_and_add(volatile _Atomic_word* __mem, int __val)
>> { return __sync_fetch_and_add(__mem, __val); }
>>
>> void
>> __attribute__ ((__unused__))
>> __atomic_add(volatile _Atomic_word* __mem, int __val)
>> { __sync_fetch_and_add(__mem, __val); }
>>}
>>
>>
>Show me assembly, please.
>
I can dig out for you something but this case, actually, is trivial,
right? You mentioned already that Intel's sync_fetch_and_add is ok and
here (for ia64), we are using exactly that.
As far as the other archs are concerned, are you familiar with GCC
inline assembly? (otherwise we can take care of that separately) I can
show you, for instance, I don't know, what we have for i486 and later:
_Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val)
{
register _Atomic_word __result;
__asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}"
: "=r" (__result), "=m" (*__mem)
: "0" (__val), "m" (*__mem));
return __result;
}
void
__attribute__ ((__unused__))
__atomic_add(volatile _Atomic_word* __mem, int __val)
{
__asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}"
: "=m" (*__mem) : "ir" (__val), "m" (*__mem));
}
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");
}
Paolo.
More information about the Libstdc++
mailing list