use native atomic increment function on Solaris
authorVladimir Kotal <Vladimir.Kotal@Oracle.COM>
Fri, 21 Jun 2019 08:31:05 +0000 (10:31 +0200)
committerMatt Caswell <matt@openssl.org>
Fri, 9 Aug 2019 12:16:41 +0000 (13:16 +0100)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9215)

crypto/threads_pthread.c

index 0d351ca6fa9ad79526d2b1af0b13a81ad2f9b663..c3fd2411db18e27d1a9ff98e1ed3561c7c658c69 100644 (file)
 #include <openssl/crypto.h>
 #include "internal/cryptlib.h"
 
+#if defined(__sun)
+# include <atomic.h>
+#endif
+
 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && !defined(OPENSSL_SYS_WINDOWS)
 
 # ifdef PTHREAD_RWLOCK_INITIALIZER
@@ -162,6 +166,12 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
         *ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
         return 1;
     }
+# elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
+    /* This will work for all future Solaris versions. */
+    if (ret != NULL) {
+        *ret = atomic_add_int_nv((volatile unsigned int *)val, amount);
+        return 1;
+    }
 # endif
     if (!CRYPTO_THREAD_write_lock(lock))
         return 0;