summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/atomic_bitmap.hpp72
-rw-r--r--src/atomic_counter.hpp42
-rw-r--r--src/atomic_ptr.hpp25
3 files changed, 92 insertions, 47 deletions
diff --git a/src/atomic_bitmap.hpp b/src/atomic_bitmap.hpp
index 1aefd27..29bdc13 100644
--- a/src/atomic_bitmap.hpp
+++ b/src/atomic_bitmap.hpp
@@ -34,8 +34,10 @@
#define ZMQ_ATOMIC_BITMAP_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_BITMAP_WINDOWS
-#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
-#define ZMQ_ATOMIC_BITMAP_SYSTEM
+#elif defined sun
+#define ZMQ_ATOMIC_COUNTER_SUN
+#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
+#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_BITMAP_MUTEX
#endif
@@ -44,7 +46,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_BITMAP_WINDOWS
#include "windows.hpp"
-#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
+#elif defined ZMQ_ATOMIC_BITMAP_SUN
#include <atomic.h>
#endif
@@ -89,7 +91,16 @@ namespace zmq
return (oldval & (bitmap_t (1) << reset_index_)) ?
true : false;
}
-#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
+#elif defined ZMQ_ATOMIC_BITMAP_GNU
+ while (true) {
+ bitmap_t oldval = value;
+ bitmap_t newval = (oldval | (bitmap_t (1) << set_index_)) &
+ ~(bitmap_t (1) << reset_index_);
+ if (__sync_val_compare_and_swap (&value, oldval, newval) == oldval)
+ return (oldval & (bitmap_t (1) << reset_index_)) ?
+ true : false;
+ }
+#elif defined ZMQ_ATOMIC_BITMAP_SUN
while (true) {
bitmap_t oldval = value;
bitmap_t newval = (oldval | (bitmap_t (1) << set_index_)) &
@@ -119,14 +130,14 @@ namespace zmq
bitmap_t tmp;
bitmap_t oldval;
__asm__ volatile(
- "ld [%5], %2 \n\t"
- "1: \n\t"
- "or %2, %0, %3 \n\t"
- "and %3, %1, %3 \n\t"
- "cas [%5], %2, %3 \n\t"
- "cmp %2, %3 \n\t"
- "bne,a,pn %%icc, 1b \n\t"
- "mov %3, %2 \n\t"
+ "ld [%5], %2 \n\t"
+ "1: \n\t"
+ "or %2, %0, %3 \n\t"
+ "and %3, %1, %3 \n\t"
+ "cas [%5], %2, %3 \n\t"
+ "cmp %2, %3 \n\t"
+ "bne,a,pn %%icc, 1b \n\t"
+ "mov %3, %2 \n\t"
: "+r" (set_val), "+r" (reset_val), "=&r" (tmp),
"=&r" (oldval), "+m" (*valptr)
: "r" (valptr)
@@ -150,7 +161,9 @@ namespace zmq
bitmap_t oldval;
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS
oldval = InterlockedExchange ((volatile LONG*) &value, newval_);
-#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
+#elif defined ZMQ_ATOMIC_BITMAP_GNU
+ oldval = __sync_lock_test_and_set (&value, newval_);
+#elif defined ZMQ_ATOMIC_BITMAP_SUN
oldval = atomic_swap_32 (&value, newval_);
#elif defined ZMQ_ATOMIC_BITMAP_X86
oldval = newval_;
@@ -201,7 +214,14 @@ namespace zmq
newval, oldval) == (LONG) oldval)
return oldval;
}
-#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
+#elif defined ZMQ_ATOMIC_BITMAP_GNU
+ while (true) {
+ bitmap_t oldval = value;
+ bitmap_t newval = oldval == 0 ? thenval_ : elseval_;
+ if (__sync_val_compare_and_swap (&value, oldval, newval) == oldval)
+ return oldval;
+ }
+#elif defined ZMQ_ATOMIC_BITMAP_SUN
while (true) {
bitmap_t oldval = value;
bitmap_t newval = oldval == 0 ? thenval_ : elseval_;
@@ -230,14 +250,14 @@ namespace zmq
bitmap_t tmp;
bitmap_t prev;
__asm__ __volatile__(
- "ld [%3], %0 \n\t"
- "mov 0, %1 \n\t"
- "cas [%3], %1, %4 \n\t"
- "cmp %0, %1 \n\t"
- "be,a,pn %%icc,1f \n\t"
- "ld [%3], %0 \n\t"
- "cas [%3], %0, %5 \n\t"
- "1: \n\t"
+ "ld [%3], %0 \n\t"
+ "mov 0, %1 \n\t"
+ "cas [%3], %1, %4 \n\t"
+ "cmp %0, %1 \n\t"
+ "be,a,pn %%icc,1f \n\t"
+ "ld [%3], %0 \n\t"
+ "cas [%3], %0, %5 \n\t"
+ "1: \n\t"
: "=&r" (tmp), "=&r" (prev), "+m" (*ptrin)
: "r" (ptrin), "r" (thenval_), "r" (elseval_)
: "cc");
@@ -270,8 +290,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS
#undef ZMQ_ATOMIC_BITMAP_WINDOWS
#endif
-#if defined ZMQ_ATOMIC_BITMAP_SYSTEM
-#undef ZMQ_ATOMIC_BITMAP_SYSTEM
+#if defined ZMQ_ATOMIC_BITMAP_GNU
+#undef ZMQ_ATOMIC_BITMAP_GNU
+#endif
+#if defined ZMQ_ATOMIC_BITMAP_SUN
+#undef ZMQ_ATOMIC_BITMAP_SUN
#endif
#if defined ZMQ_ATOMIC_BITMAP_X86
#undef ZMQ_ATOMIC_BITMAP_X86
@@ -284,3 +307,4 @@ namespace zmq
#endif
#endif
+
diff --git a/src/atomic_counter.hpp b/src/atomic_counter.hpp
index 4a77928..5e05300 100644
--- a/src/atomic_counter.hpp
+++ b/src/atomic_counter.hpp
@@ -31,8 +31,10 @@
#define ZMQ_ATOMIC_COUNTER_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_COUNTER_WINDOWS
-#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
-#define ZMQ_ATOMIC_COUNTER_SYSTEM
+#elif defined sun
+#define ZMQ_ATOMIC_COUNTER_SUN
+#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
+#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_COUNTER_MUTEX
#endif
@@ -41,7 +43,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_COUNTER_WINDOWS
#include "windows.hpp"
-#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM
+#elif defined ZMQ_ATOMIC_COUNTER_SUN
#include <atomic.h>
#endif
@@ -79,25 +81,27 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS
old_value = InterlockedExchangeAdd ((LONG*) &value, increment_);
-#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM
+#elif defined ZMQ_ATOMIC_COUNTER_GNU
+ old_value = __sync_fetch_and_add (&value, increment_);
+#elif defined ZMQ_ATOMIC_COUNTER_SUN
integer_t new_value = atomic_add_32_nv (&value, increment_);
old_value = new_value - increment_;
#elif defined ZMQ_ATOMIC_COUNTER_X86
__asm__ volatile (
- "lock; xadd %0, %1 \n\t"
+ "lock; xadd %0, %1 \n\t"
: "=r" (old_value), "=m" (value)
: "0" (increment_), "m" (value)
: "cc", "memory");
#elif defined ZMQ_ATOMIC_COUNTER_SPARC
integer_t tmp;
__asm__ volatile (
- "ld [%4], %0 \n\t"
- "1: \n\t"
- "add %0, %3, %1 \n\t"
- "cas [%4], %0, %1 \n\t"
- "cmp %0, %1 \n\t"
- "bne,a,pn %%icc, 1b \n\t"
- "mov %1, %0 \n\t"
+ "ld [%4], %0 \n\t"
+ "1: \n\t"
+ "add %0, %3, %1 \n\t"
+ "cas [%4], %0, %1 \n\t"
+ "cmp %0, %1 \n\t"
+ "bne,a,pn %%icc, 1b \n\t"
+ "mov %1, %0 \n\t"
: "=&r" (old_value), "=&r" (tmp), "=m" (value)
: "r" (increment_), "r" (&value)
: "cc", "memory");
@@ -119,7 +123,11 @@ namespace zmq
LONG delta = - ((LONG) decrement);
integer_t old = InterlockedExchangeAdd ((LONG*) &value, delta);
return old - decrement != 0;
-#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM
+#elif defined ZMQ_ATOMIC_COUNTER_GNU
+ int32_t delta = - ((int32_t) decrement);
+ integer_t nv = __sync_fetch_and_add (&value, delta);
+ return nv != 0;
+#elif defined ZMQ_ATOMIC_COUNTER_SUN
int32_t delta = - ((int32_t) decrement);
integer_t nv = atomic_add_32_nv (&value, delta);
return nv != 0;
@@ -180,8 +188,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS
#undef ZMQ_ATOMIC_COUNTER_WINDOWS
#endif
-#if defined ZMQ_ATOMIC_COUNTER_SYSTEM
-#undef ZMQ_ATOMIC_COUNTER_SYSTEM
+#if defined ZMQ_ATOMIC_COUNTER_GNU
+#undef ZMQ_ATOMIC_COUNTER_GNU
+#endif
+#if defined ZMQ_ATOMIC_COUNTER_SUN
+#undef ZMQ_ATOMIC_COUNTER_SUN
#endif
#if defined ZMQ_ATOMIC_COUNTER_X86
#undef ZMQ_ATOMIC_COUNTER_X86
@@ -194,3 +205,4 @@ namespace zmq
#endif
#endif
+
diff --git a/src/atomic_ptr.hpp b/src/atomic_ptr.hpp
index 9f2e759..5530736 100644
--- a/src/atomic_ptr.hpp
+++ b/src/atomic_ptr.hpp
@@ -17,7 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#ifndef __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
#define __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
@@ -31,8 +30,10 @@
#define ZMQ_ATOMIC_PTR_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_PTR_WINDOWS
-#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
-#define ZMQ_ATOMIC_PTR_SYSTEM
+#elif defined sun
+#define ZMQ_ATOMIC_COUNTER_SUN
+#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
+#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_PTR_MUTEX
#endif
@@ -41,7 +42,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_PTR_WINDOWS
#include "windows.hpp"
-#elif defined ZMQ_ATOMIC_PTR_SYSTEM
+#elif defined ZMQ_ATOMIC_PTR_SUN
#include <atomic.h>
#endif
@@ -79,7 +80,9 @@ namespace zmq
{
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return (T*) InterlockedExchangePointer ((PVOID*) &ptr, val_);
-#elif defined ZMQ_ATOMIC_PTR_SYSTEM
+#elif defined ZMQ_ATOMIC_PTR_GNU
+ return (T*) __sync_lock_test_and_set (&ptr, val_);
+#elif defined ZMQ_ATOMIC_PTR_SUN
return (T*) atomic_swap_ptr (&ptr, val_);
#elif defined ZMQ_ATOMIC_PTR_X86
T *old;
@@ -125,7 +128,9 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return (T*) InterlockedCompareExchangePointer (
(volatile PVOID*) &ptr, val_, cmp_);
-#elif defined ZMQ_ATOMIC_PTR_SYSTEM
+#elif defined ZMQ_ATOMIC_PTR_GNU
+ return (T*) __sync_val_compare_and_swap (&ptr, cmp_, val_);
+#elif defined ZMQ_ATOMIC_PTR_SUN
return (T*) atomic_cas_ptr (&ptr, cmp_, val_);
#elif defined ZMQ_ATOMIC_PTR_X86
T *old;
@@ -173,8 +178,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS
#undef ZMQ_ATOMIC_PTR_WINDOWS
#endif
-#if defined ZMQ_ATOMIC_PTR_SYSTEM
-#undef ZMQ_ATOMIC_PTR_SYSTEM
+#if defined ZMQ_ATOMIC_PTR_GNU
+#undef ZMQ_ATOMIC_PTR_GNU
+#endif
+#if defined ZMQ_ATOMIC_PTR_SUN
+#undef ZMQ_ATOMIC_PTR_SUN
#endif
#if defined ZMQ_ATOMIC_PTR_X86
#undef ZMQ_ATOMIC_PTR_X86
@@ -187,3 +195,4 @@ namespace zmq
#endif
#endif
+