aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@cygnus.com>1999-05-07 10:16:09 +0000
committerUlrich Drepper <drepper@cygnus.com>1999-05-07 10:16:09 +0000
commit5eec400f26d4027965f32af757693cbf8a745217 (patch)
tree67c931fedbc81397924fffc01bd713931f0517e9
parent6232525d6520333266027b36d6729c00b0355f22 (diff)
(class basic_string::Rep): Make release member function thread-safe for
ix86 (x>=4) and UltraSPARC. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@26820 138bc75d-0d04-0410-961f-82ee72b054a4
-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 *);