atomic operations for Solaris 9; unused 64 bit atomic operations removed
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 6 Nov 2013 20:59:23 +0000 (22:59 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 6 Nov 2013 20:59:23 +0000 (22:59 +0200)
INSTALL
configure.ac
include/nms_threads.h
src/libnetxms/Makefile.am

diff --git a/INSTALL b/INSTALL
index 007e939..6e90e07 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -1,7 +1,7 @@
 Installation Instructions
 *************************
 
-Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
+Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
 Inc.
 
    Copying and distribution of this file, with or without modification,
index 8738f4d..f24dc2a 100644 (file)
@@ -684,15 +684,15 @@ case "$PLATFORM" in
       fi
       ;;
    SunOS)
-      CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
+      CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -O2"
       LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
       export LD_LIBRARY_PATH
       ;;
    Linux)
-      CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+      CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -O2"
       ;;
    Darwin)
-      CPPFLAGS="$CPPFLAGS -Wno-deprecated-declarations"
+      CPPFLAGS="$CPPFLAGS -Wno-deprecated-declarations -O2"
       ;;
    *)
       ;;
@@ -1550,6 +1550,17 @@ if test "x$PLATFORM" = "xAIX"; then
 fi
 
 
+#--------------------------------------------------------------------
+# Solaris specific checks
+#--------------------------------------------------------------------
+
+if test "x$PLATFORM" = "xSunOS"; then
+       AC_CHECK_FUNCS([atomic_inc_32_nv atomic_dec_32_nv],,,[
+#include <sys/atomic.h>
+       ])
+fi
+
+
 #--------------------------------------------------------------------
 # HP-UX specific checks
 #--------------------------------------------------------------------
index ba6b25d..3cf5bc1 100644 (file)
@@ -896,21 +896,31 @@ inline THREAD GetCurrentThreadId()
 #ifdef _WIN32
 
 typedef volatile LONG VolatileCounter;
-typedef volatile LONGLONG VolatileCounter64;
 
 #else
 
 #if defined(__sun)
 
 typedef volatile uint32_t VolatileCounter;
-typedef volatile uint64_t VolatileCounter64;
+
+#if !HAVE_ATOMIC_INC_32_NV
+extern "C" volatile uint32_t solaris9_atomic_inc32(volatile uint32_t *v);
+#endif
+
+#if !HAVE_ATOMIC_DEC_32_NV
+extern "C" volatile uint32_t solaris9_atomic_dec32(volatile uint32_t *v);
+#endif
 
 /**
  * Atomically increment 32-bit value by 1
  */
 inline VolatileCounter InterlockedIncrement(VolatileCounter *v)
 {
+#if HAVE_ATOMIC_INC_32_NV
    return atomic_inc_32_nv(v);
+#else
+   return solaris9_atomic_inc32(v);
+#endif
 }
 
 /**
@@ -918,29 +928,16 @@ inline VolatileCounter InterlockedIncrement(VolatileCounter *v)
  */
 inline VolatileCounter InterlockedDecrement(VolatileCounter *v)
 {
+#if HAVE_ATOMIC_DEC_32_NV
    return atomic_dec_32_nv(v);
-}
-
-/**
- * Atomically increment 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedIncrement64(VolatileCounter64 *v)
-{
-   return atomic_inc_64_nv(v);
-}
-
-/**
- * Atomically decrement 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedDecrement64(VolatileCounter64 *v)
-{
-   return atomic_dec_64_nv(v);
+#else
+   return solaris9_atomic_dec32(v);
+#endif
 }
 
 #elif defined(__HP_aCC)
 
 typedef volatile uint32_t VolatileCounter;
-typedef volatile uint64_t VolatileCounter64;
 
 /**
  * Atomically increment 32-bit value by 1
@@ -968,36 +965,9 @@ inline VolatileCounter InterlockedDecrement(VolatileCounter *v)
 #endif
 }
 
-/**
- * Atomically increment 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedIncrement64(VolatileCounter64 *v)
-{
-#if HAVE_ATOMIC_H
-   return atomic_inc_64(v) + 1;
-#else
-   _Asm_mf(_DFLT_FENCE);
-   return (uint64_t)_Asm_fetchadd(_FASZ_D, _SEM_ACQ, (void *)v, +1, _LDHINT_NONE) + 1;
-#endif
-}
-
-/**
- * Atomically decrement 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedDecrement64(VolatileCounter64 *v)
-{
-#if HAVE_ATOMIC_H
-   return atomic_dec_64(v) - 1;
-#else
-   _Asm_mf(_DFLT_FENCE);
-   return (uint64_t)_Asm_fetchadd(_FASZ_D, _SEM_ACQ, (void *)v, -1, _LDHINT_NONE) - 1;
-#endif
-}
-
 #else /* not Solaris nor HP-UX */
 
 typedef volatile INT32 VolatileCounter;
-typedef volatile INT64 VolatileCounter64;
 
 /**
  * Atomically increment 32-bit value by 1
@@ -1033,48 +1003,6 @@ inline VolatileCounter InterlockedDecrement(VolatileCounter *v)
 #endif
 }
 
-#if (defined(__IBMC__) || defined(__IBMCPP__)) && !defined(__LP64__)
-
-/* interlocked ops on 64bit values not supported by 32 bit xlC */
-
-#else
-
-/**
- * Atomically increment 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedIncrement64(VolatileCounter64 *v)
-{
-#if (defined(__IBMC__) || defined(__IBMCPP__)) && !HAVE_DECL___SYNC_ADD_AND_FETCH
-   VolatileCounter64 oldval;
-   do
-   {
-      oldval = __ldarx(v);
-   } while(__stdcx(v, oldval + 1) == 0);
-   return oldval + 1;
-#else
-   return __sync_add_and_fetch(v, 1);
-#endif
-}
-
-/**
- * Atomically decrement 64-bit value by 1
- */
-inline VolatileCounter64 InterlockedDecrement64(VolatileCounter64 *v)
-{
-#if (defined(__IBMC__) || defined(__IBMCPP__)) && !HAVE_DECL___SYNC_ADD_AND_FETCH
-   VolatileCounter64 oldval;
-   do
-   {
-      oldval = __ldarx(v);
-   } while(__stdcx(v, oldval - 1) == 0);
-   return oldval - 1;
-#else
-   return __sync_sub_and_fetch(v, 1);
-#endif
-}
-
-#endif   /* __IBMC__ */
-
 #endif   /* __sun */
 
 #endif   /* _WIN32 */
index 087085f..3b2ba70 100644 (file)
@@ -2,10 +2,10 @@ SOURCES = agent.cpp array.cpp base64.cpp config.cpp crypto.cpp dirw_unix.c \
          gen_uuid.c geolocation.cpp getopt.c dload.cpp hash.cpp ice.c \
          icmp.cpp log.cpp main.cpp md5.cpp message.cpp msgwq.cpp net.cpp \
          nxcp.cpp qsort.c queue.cpp rwlock.cpp scandir.c serial.cpp \
-         sha1.cpp string.cpp stringlist.cpp strmap.cpp strmapbase.cpp \
-         strset.cpp strtoll.c strtoull.c table.cpp threads.cpp tools.cpp \
-         unicode.cpp uuid.c wcstoll.c wcstoull.c xml.cpp \
-         wcscasecmp.cpp wcsncasecmp.cpp
+         sha1.cpp solaris9_atomic.c string.cpp stringlist.cpp strmap.cpp \
+         strmapbase.cpp strset.cpp strtoll.c strtoull.c table.cpp \
+         threads.cpp tools.cpp unicode.cpp uuid.c wcstoll.c wcstoull.c \
+         xml.cpp wcscasecmp.cpp wcsncasecmp.cpp
 
 lib_LTLIBRARIES = libnetxms.la