mcatan 2004/05/08 13:50:01
Modified: src thread.cpp
Log:
added thread-safe increment/decrement for solaris specific compilator
Revision Changes Path
1.11 +31 -0 logging-log4cxx/src/thread.cpp
Index: thread.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/thread.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- thread.cpp 24 Apr 2004 08:13:22 -0000 1.10
+++ thread.cpp 8 May 2004 20:50:01 -0000 1.11
@@ -163,6 +163,30 @@
#ifdef __GLIBCPP__
#include <bits/atomicity.h>
+#else
+#if defined(sparc) && defined(__SUNPRO_CC)
+extern "C" long sparc_atomic_add_32 (volatile long* p, long val);
+
+static void asm_code()
+{
+ asm(".align 8"); \
+ asm(".global sparc_atomic_add_32"); \
+ asm(".type sparc_atomic_add_32, #function"); \
+
+ asm("sparc_atomic_add_32:");
+ asm(" membar #Lookaside | #LoadLoad | #LoadStore | #StoreLoad");
+ asm(" ld [%o0], %l0"); // l0 = *p;
+ asm(" add %l0, %o1, %l2"); // l2 = l0 + val
+ asm(" cas [%o0], %l0, %l2"); // if (*p = l0) swap([o0], l2);
+ asm(" cmp %l0, %l2"); // does it match
+ asm(" bne sparc_atomic_add_32");// if not try again
+ asm(" nop"); // delay slot filler
+ asm(" add %l2, %o1, %o0"); // set return code
+ asm(" membar #Lookaside | #LoadLoad | #LoadStore | #StoreLoad");
+ asm("retl");
+ asm("nop");
+}
+#endif
#endif
long Thread::InterlockedIncrement(volatile long * val)
@@ -177,6 +201,9 @@
: "0" (1), "m" (*val));
return ret+1;
+#elif defined(sparc) && defined(__SUNPRO_CC)
+ sparc_atomic_add_32(val, 1);
+ return *val;
#elif defined(HAVE_MS_THREAD)
#if _MSC_VER == 1200 // MSDEV 6
return ::InterlockedIncrement((long *)val);
@@ -199,6 +226,10 @@
: "0" (-1), "m" (*val));
return ret-1;
+
+#elif defined(sparc) && defined(__SUNPRO_CC)
+ sparc_atomic_add_32(val, -1);
+ return *val;
#elif defined(HAVE_MS_THREAD)
#if _MSC_VER == 1200 // MSDEV 6
return ::InterlockedDecrement((long *)val);