Return a value from atomic read on Windows.
authorPauli <paul.dale@oracle.com>
Tue, 10 Oct 2017 23:47:54 +0000 (09:47 +1000)
committerPauli <paul.dale@oracle.com>
Tue, 10 Oct 2017 23:47:54 +0000 (09:47 +1000)
Use a read lock when reading using pthreads.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4517)

crypto/threads_pthread.c
crypto/threads_win.c

index 34be314..3aeef21 100644 (file)
@@ -177,7 +177,7 @@ int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock)
         return 1;
     }
 # endif
-    if (!CRYPTO_THREAD_write_lock(lock))
+    if (!CRYPTO_THREAD_read_lock(lock))
         return 0;
 
     *ret  = *val;
index ab2eb25..f222aa5 100644 (file)
@@ -135,7 +135,7 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
 
 int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock)
 {
-    InterlockedCompareExchange(val, 0, 0);
+    *ret = InterlockedCompareExchange(val, 0, 0);
     return 1;
 }