summaryrefslogtreecommitdiff
path: root/libstdc++
diff options
context:
space:
mode:
authordrepper <drepper@138bc75d-0d04-0410-961f-82ee72b054a4>1999-05-07 10:16:09 +0000
committerdrepper <drepper@138bc75d-0d04-0410-961f-82ee72b054a4>1999-05-07 10:16:09 +0000
commit928c87970851b1da28fbedec0819f959988d3350 (patch)
tree67c931fedbc81397924fffc01bd713931f0517e9 /libstdc++
parenta7a3002e62f4a75b24b671c55f6251b068cf86fd (diff)
downloadgcc-928c87970851b1da28fbedec0819f959988d3350.tar.gz
(class basic_string::Rep): Make release member function thread-safe for
ix86 (x>=4) and UltraSPARC. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26820 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++')
-rw-r--r--libstdc++/std/bastring.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/libstdc++/std/bastring.h b/libstdc++/std/bastring.h
index f188628cc77..6206713b6c9 100644
--- a/libstdc++/std/bastring.h
+++ b/libstdc++/std/bastring.h
@@ -73,7 +73,34 @@ private:
charT* data () { return reinterpret_cast<charT *>(this + 1); }
charT& operator[] (size_t s) { return data () [s]; }
charT* grab () { if (selfish) return clone (); ++ref; return data (); }
+#if defined __i486__ || defined __i586__ || defined __i686__
+ void release ()
+ {
+ size_t __val;
+ asm ("lock; xaddl %0, %2"
+ : "=r" (__val) : "0" (-1), "m" (ref) : "memory");
+ if (__val == 1)
+ delete this;
+ }
+#elif defined __sparcv9__
+ void release ()
+ {
+ size_t __newval, __oldval = ref;
+ do
+ {
+ __newval = __oldval - 1;
+ __asm__ ("cas [%4], %2, %0"
+ : "=r" (__oldval), "=m" (ref)
+ : "r" (__oldval), "m" (ref), "r"(&(ref)), "0" (__newval));
+ }
+ while (__newval != __oldval);
+
+ if (__oldval == 0)
+ delete this;
+ }
+#else
void release () { if (--ref == 0) delete this; }
+#endif
inline static void * operator new (size_t, size_t);
inline static void operator delete (void *);