diff options
author | Pauli <paul.dale@oracle.com> | 2017-10-09 06:39:43 +0200 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2017-10-10 00:45:53 +0200 |
commit | 30ff41beab5d8a53cbcbdab4109b32b9ef5c0f6e (patch) | |
tree | d807a734652467cb791af4cfdfe5330080dca5d1 /crypto/threads_pthread.c | |
parent | Add a CRYPTO_atomic_read call which allows an int variable to be read (diff) | |
download | openssl-30ff41beab5d8a53cbcbdab4109b32b9ef5c0f6e.tar.xz openssl-30ff41beab5d8a53cbcbdab4109b32b9ef5c0f6e.zip |
Add atomic write call
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4414)
Diffstat (limited to 'crypto/threads_pthread.c')
-rw-r--r-- | crypto/threads_pthread.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 3f8ada2c37..34be314f1f 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -188,6 +188,25 @@ int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock) return 1; } +int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock) +{ +# if defined(__GNUC__) && defined(__ATOMIC_RELEASE) + if (__atomic_is_lock_free(sizeof(*val), val)) { + __atomic_store(val, &n, __ATOMIC_RELEASE); + return 1; + } +# endif + if (!CRYPTO_THREAD_write_lock(lock)) + return 0; + + *val = n; + + if (!CRYPTO_THREAD_unlock(lock)) + return 0; + + return 1; +} + # ifdef OPENSSL_SYS_UNIX static pthread_once_t fork_once_control = PTHREAD_ONCE_INIT; |