Commit 7cb076e5 authored by Steven McCoy's avatar Steven McCoy Committed by Martin Sustrik

Defer NetBSD atomic ops to GCC builtins. Revert Sun atomic ops #define.

parent ad6fa9d0
...@@ -34,8 +34,10 @@ ...@@ -34,8 +34,10 @@
#define ZMQ_ATOMIC_BITMAP_SPARC #define ZMQ_ATOMIC_BITMAP_SPARC
#elif defined ZMQ_HAVE_WINDOWS #elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_BITMAP_WINDOWS #define ZMQ_ATOMIC_BITMAP_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD) #elif defined sun
#define ZMQ_ATOMIC_BITMAP_SYSTEM #define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else #else
#define ZMQ_ATOMIC_BITMAP_MUTEX #define ZMQ_ATOMIC_BITMAP_MUTEX
#endif #endif
...@@ -44,7 +46,7 @@ ...@@ -44,7 +46,7 @@
#include "mutex.hpp" #include "mutex.hpp"
#elif defined ZMQ_ATOMIC_BITMAP_WINDOWS #elif defined ZMQ_ATOMIC_BITMAP_WINDOWS
#include "windows.hpp" #include "windows.hpp"
#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM #elif defined ZMQ_ATOMIC_BITMAP_SUN
#include <atomic.h> #include <atomic.h>
#endif #endif
...@@ -89,7 +91,16 @@ namespace zmq ...@@ -89,7 +91,16 @@ namespace zmq
return (oldval & (bitmap_t (1) << reset_index_)) ? return (oldval & (bitmap_t (1) << reset_index_)) ?
true : false; 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) { while (true) {
bitmap_t oldval = value; bitmap_t oldval = value;
bitmap_t newval = (oldval | (bitmap_t (1) << set_index_)) & bitmap_t newval = (oldval | (bitmap_t (1) << set_index_)) &
...@@ -119,14 +130,14 @@ namespace zmq ...@@ -119,14 +130,14 @@ namespace zmq
bitmap_t tmp; bitmap_t tmp;
bitmap_t oldval; bitmap_t oldval;
__asm__ volatile( __asm__ volatile(
"ld [%5], %2 \n\t" "ld [%5], %2 \n\t"
"1: \n\t" "1: \n\t"
"or %2, %0, %3 \n\t" "or %2, %0, %3 \n\t"
"and %3, %1, %3 \n\t" "and %3, %1, %3 \n\t"
"cas [%5], %2, %3 \n\t" "cas [%5], %2, %3 \n\t"
"cmp %2, %3 \n\t" "cmp %2, %3 \n\t"
"bne,a,pn %%icc, 1b \n\t" "bne,a,pn %%icc, 1b \n\t"
"mov %3, %2 \n\t" "mov %3, %2 \n\t"
: "+r" (set_val), "+r" (reset_val), "=&r" (tmp), : "+r" (set_val), "+r" (reset_val), "=&r" (tmp),
"=&r" (oldval), "+m" (*valptr) "=&r" (oldval), "+m" (*valptr)
: "r" (valptr) : "r" (valptr)
...@@ -150,7 +161,9 @@ namespace zmq ...@@ -150,7 +161,9 @@ namespace zmq
bitmap_t oldval; bitmap_t oldval;
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS #if defined ZMQ_ATOMIC_BITMAP_WINDOWS
oldval = InterlockedExchange ((volatile LONG*) &value, newval_); 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_); oldval = atomic_swap_32 (&value, newval_);
#elif defined ZMQ_ATOMIC_BITMAP_X86 #elif defined ZMQ_ATOMIC_BITMAP_X86
oldval = newval_; oldval = newval_;
...@@ -201,7 +214,14 @@ namespace zmq ...@@ -201,7 +214,14 @@ namespace zmq
newval, oldval) == (LONG) oldval) newval, oldval) == (LONG) oldval)
return 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) { while (true) {
bitmap_t oldval = value; bitmap_t oldval = value;
bitmap_t newval = oldval == 0 ? thenval_ : elseval_; bitmap_t newval = oldval == 0 ? thenval_ : elseval_;
...@@ -230,14 +250,14 @@ namespace zmq ...@@ -230,14 +250,14 @@ namespace zmq
bitmap_t tmp; bitmap_t tmp;
bitmap_t prev; bitmap_t prev;
__asm__ __volatile__( __asm__ __volatile__(
"ld [%3], %0 \n\t" "ld [%3], %0 \n\t"
"mov 0, %1 \n\t" "mov 0, %1 \n\t"
"cas [%3], %1, %4 \n\t" "cas [%3], %1, %4 \n\t"
"cmp %0, %1 \n\t" "cmp %0, %1 \n\t"
"be,a,pn %%icc,1f \n\t" "be,a,pn %%icc,1f \n\t"
"ld [%3], %0 \n\t" "ld [%3], %0 \n\t"
"cas [%3], %0, %5 \n\t" "cas [%3], %0, %5 \n\t"
"1: \n\t" "1: \n\t"
: "=&r" (tmp), "=&r" (prev), "+m" (*ptrin) : "=&r" (tmp), "=&r" (prev), "+m" (*ptrin)
: "r" (ptrin), "r" (thenval_), "r" (elseval_) : "r" (ptrin), "r" (thenval_), "r" (elseval_)
: "cc"); : "cc");
...@@ -270,8 +290,11 @@ namespace zmq ...@@ -270,8 +290,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS #if defined ZMQ_ATOMIC_BITMAP_WINDOWS
#undef ZMQ_ATOMIC_BITMAP_WINDOWS #undef ZMQ_ATOMIC_BITMAP_WINDOWS
#endif #endif
#if defined ZMQ_ATOMIC_BITMAP_SYSTEM #if defined ZMQ_ATOMIC_BITMAP_GNU
#undef ZMQ_ATOMIC_BITMAP_SYSTEM #undef ZMQ_ATOMIC_BITMAP_GNU
#endif
#if defined ZMQ_ATOMIC_BITMAP_SUN
#undef ZMQ_ATOMIC_BITMAP_SUN
#endif #endif
#if defined ZMQ_ATOMIC_BITMAP_X86 #if defined ZMQ_ATOMIC_BITMAP_X86
#undef ZMQ_ATOMIC_BITMAP_X86 #undef ZMQ_ATOMIC_BITMAP_X86
...@@ -284,3 +307,4 @@ namespace zmq ...@@ -284,3 +307,4 @@ namespace zmq
#endif #endif
#endif #endif
...@@ -31,8 +31,10 @@ ...@@ -31,8 +31,10 @@
#define ZMQ_ATOMIC_COUNTER_SPARC #define ZMQ_ATOMIC_COUNTER_SPARC
#elif defined ZMQ_HAVE_WINDOWS #elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_COUNTER_WINDOWS #define ZMQ_ATOMIC_COUNTER_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD) #elif defined sun
#define ZMQ_ATOMIC_COUNTER_SYSTEM #define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else #else
#define ZMQ_ATOMIC_COUNTER_MUTEX #define ZMQ_ATOMIC_COUNTER_MUTEX
#endif #endif
...@@ -41,7 +43,7 @@ ...@@ -41,7 +43,7 @@
#include "mutex.hpp" #include "mutex.hpp"
#elif defined ZMQ_ATOMIC_COUNTER_WINDOWS #elif defined ZMQ_ATOMIC_COUNTER_WINDOWS
#include "windows.hpp" #include "windows.hpp"
#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM #elif defined ZMQ_ATOMIC_COUNTER_SUN
#include <atomic.h> #include <atomic.h>
#endif #endif
...@@ -79,25 +81,27 @@ namespace zmq ...@@ -79,25 +81,27 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS #if defined ZMQ_ATOMIC_COUNTER_WINDOWS
old_value = InterlockedExchangeAdd ((LONG*) &value, increment_); 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_); integer_t new_value = atomic_add_32_nv (&value, increment_);
old_value = new_value - increment_; old_value = new_value - increment_;
#elif defined ZMQ_ATOMIC_COUNTER_X86 #elif defined ZMQ_ATOMIC_COUNTER_X86
__asm__ volatile ( __asm__ volatile (
"lock; xadd %0, %1 \n\t" "lock; xadd %0, %1 \n\t"
: "=r" (old_value), "=m" (value) : "=r" (old_value), "=m" (value)
: "0" (increment_), "m" (value) : "0" (increment_), "m" (value)
: "cc", "memory"); : "cc", "memory");
#elif defined ZMQ_ATOMIC_COUNTER_SPARC #elif defined ZMQ_ATOMIC_COUNTER_SPARC
integer_t tmp; integer_t tmp;
__asm__ volatile ( __asm__ volatile (
"ld [%4], %0 \n\t" "ld [%4], %0 \n\t"
"1: \n\t" "1: \n\t"
"add %0, %3, %1 \n\t" "add %0, %3, %1 \n\t"
"cas [%4], %0, %1 \n\t" "cas [%4], %0, %1 \n\t"
"cmp %0, %1 \n\t" "cmp %0, %1 \n\t"
"bne,a,pn %%icc, 1b \n\t" "bne,a,pn %%icc, 1b \n\t"
"mov %1, %0 \n\t" "mov %1, %0 \n\t"
: "=&r" (old_value), "=&r" (tmp), "=m" (value) : "=&r" (old_value), "=&r" (tmp), "=m" (value)
: "r" (increment_), "r" (&value) : "r" (increment_), "r" (&value)
: "cc", "memory"); : "cc", "memory");
...@@ -119,7 +123,11 @@ namespace zmq ...@@ -119,7 +123,11 @@ namespace zmq
LONG delta = - ((LONG) decrement); LONG delta = - ((LONG) decrement);
integer_t old = InterlockedExchangeAdd ((LONG*) &value, delta); integer_t old = InterlockedExchangeAdd ((LONG*) &value, delta);
return old - decrement != 0; 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); int32_t delta = - ((int32_t) decrement);
integer_t nv = atomic_add_32_nv (&value, delta); integer_t nv = atomic_add_32_nv (&value, delta);
return nv != 0; return nv != 0;
...@@ -180,8 +188,11 @@ namespace zmq ...@@ -180,8 +188,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS #if defined ZMQ_ATOMIC_COUNTER_WINDOWS
#undef ZMQ_ATOMIC_COUNTER_WINDOWS #undef ZMQ_ATOMIC_COUNTER_WINDOWS
#endif #endif
#if defined ZMQ_ATOMIC_COUNTER_SYSTEM #if defined ZMQ_ATOMIC_COUNTER_GNU
#undef ZMQ_ATOMIC_COUNTER_SYSTEM #undef ZMQ_ATOMIC_COUNTER_GNU
#endif
#if defined ZMQ_ATOMIC_COUNTER_SUN
#undef ZMQ_ATOMIC_COUNTER_SUN
#endif #endif
#if defined ZMQ_ATOMIC_COUNTER_X86 #if defined ZMQ_ATOMIC_COUNTER_X86
#undef ZMQ_ATOMIC_COUNTER_X86 #undef ZMQ_ATOMIC_COUNTER_X86
...@@ -194,3 +205,4 @@ namespace zmq ...@@ -194,3 +205,4 @@ namespace zmq
#endif #endif
#endif #endif
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ZMQ_ATOMIC_PTR_HPP_INCLUDED__ #ifndef __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
#define __ZMQ_ATOMIC_PTR_HPP_INCLUDED__ #define __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
...@@ -31,8 +30,10 @@ ...@@ -31,8 +30,10 @@
#define ZMQ_ATOMIC_PTR_SPARC #define ZMQ_ATOMIC_PTR_SPARC
#elif defined ZMQ_HAVE_WINDOWS #elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_PTR_WINDOWS #define ZMQ_ATOMIC_PTR_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD) #elif defined sun
#define ZMQ_ATOMIC_PTR_SYSTEM #define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else #else
#define ZMQ_ATOMIC_PTR_MUTEX #define ZMQ_ATOMIC_PTR_MUTEX
#endif #endif
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
#include "mutex.hpp" #include "mutex.hpp"
#elif defined ZMQ_ATOMIC_PTR_WINDOWS #elif defined ZMQ_ATOMIC_PTR_WINDOWS
#include "windows.hpp" #include "windows.hpp"
#elif defined ZMQ_ATOMIC_PTR_SYSTEM #elif defined ZMQ_ATOMIC_PTR_SUN
#include <atomic.h> #include <atomic.h>
#endif #endif
...@@ -79,7 +80,9 @@ namespace zmq ...@@ -79,7 +80,9 @@ namespace zmq
{ {
#if defined ZMQ_ATOMIC_PTR_WINDOWS #if defined ZMQ_ATOMIC_PTR_WINDOWS
return (T*) InterlockedExchangePointer ((PVOID*) &ptr, val_); 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_); return (T*) atomic_swap_ptr (&ptr, val_);
#elif defined ZMQ_ATOMIC_PTR_X86 #elif defined ZMQ_ATOMIC_PTR_X86
T *old; T *old;
...@@ -125,7 +128,9 @@ namespace zmq ...@@ -125,7 +128,9 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS #if defined ZMQ_ATOMIC_PTR_WINDOWS
return (T*) InterlockedCompareExchangePointer ( return (T*) InterlockedCompareExchangePointer (
(volatile PVOID*) &ptr, val_, cmp_); (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_); return (T*) atomic_cas_ptr (&ptr, cmp_, val_);
#elif defined ZMQ_ATOMIC_PTR_X86 #elif defined ZMQ_ATOMIC_PTR_X86
T *old; T *old;
...@@ -173,8 +178,11 @@ namespace zmq ...@@ -173,8 +178,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS #if defined ZMQ_ATOMIC_PTR_WINDOWS
#undef ZMQ_ATOMIC_PTR_WINDOWS #undef ZMQ_ATOMIC_PTR_WINDOWS
#endif #endif
#if defined ZMQ_ATOMIC_PTR_SYSTEM #if defined ZMQ_ATOMIC_PTR_GNU
#undef ZMQ_ATOMIC_PTR_SYSTEM #undef ZMQ_ATOMIC_PTR_GNU
#endif
#if defined ZMQ_ATOMIC_PTR_SUN
#undef ZMQ_ATOMIC_PTR_SUN
#endif #endif
#if defined ZMQ_ATOMIC_PTR_X86 #if defined ZMQ_ATOMIC_PTR_X86
#undef ZMQ_ATOMIC_PTR_X86 #undef ZMQ_ATOMIC_PTR_X86
...@@ -187,3 +195,4 @@ namespace zmq ...@@ -187,3 +195,4 @@ namespace zmq
#endif #endif
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment