summaryrefslogtreecommitdiff
path: root/crypto/threads_pthread.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/threads_pthread.c')
-rw-r--r--crypto/threads_pthread.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index dfa338b11734..e1f931a502b4 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -14,7 +14,7 @@
#include "internal/cryptlib.h"
#if defined(__sun)
-# include <atomic.h>
+#include <atomic.h>
#endif
#if defined(__apple_build_version__) && __apple_build_version__ < 6000000
@@ -31,26 +31,26 @@
#if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && !defined(OPENSSL_SYS_WINDOWS)
-# if defined(OPENSSL_SYS_UNIX)
-# include <sys/types.h>
-# include <unistd.h>
+#if defined(OPENSSL_SYS_UNIX)
+#include <sys/types.h>
+#include <unistd.h>
#endif
-# include <assert.h>
+#include <assert.h>
/*
* The Non-Stop KLT thread model currently seems broken in its rwlock
* implementation
* Likewise is there a problem with the glibc implementation on riscv.
*/
-# if defined(PTHREAD_RWLOCK_INITIALIZER) && !defined(_KLT_MODEL_) \
- && !defined(__riscv)
-# define USE_RWLOCK
-# endif
+#if defined(PTHREAD_RWLOCK_INITIALIZER) && !defined(_KLT_MODEL_) \
+ && !defined(__riscv)
+#define USE_RWLOCK
+#endif
CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
{
-# ifdef USE_RWLOCK
+#ifdef USE_RWLOCK
CRYPTO_RWLOCK *lock;
if ((lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t))) == NULL) {
@@ -62,7 +62,7 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
OPENSSL_free(lock);
return NULL;
}
-# else
+#else
pthread_mutexattr_t attr;
CRYPTO_RWLOCK *lock;
@@ -75,13 +75,13 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
* We don't use recursive mutexes, but try to catch errors if we do.
*/
pthread_mutexattr_init(&attr);
-# if !defined (__TANDEM) && !defined (_SPT_MODEL_)
-# if !defined(NDEBUG) && !defined(OPENSSL_NO_MUTEX_ERRORCHECK)
+#if !defined(__TANDEM) && !defined(_SPT_MODEL_)
+#if !defined(NDEBUG) && !defined(OPENSSL_NO_MUTEX_ERRORCHECK)
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
-# endif
-# else
+#endif
+#else
/* The SPT Thread Library does not define MUTEX attributes. */
-# endif
+#endif
if (pthread_mutex_init(lock, &attr) != 0) {
pthread_mutexattr_destroy(&attr);
@@ -90,52 +90,52 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
}
pthread_mutexattr_destroy(&attr);
-# endif
+#endif
return lock;
}
__owur int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
{
-# ifdef USE_RWLOCK
+#ifdef USE_RWLOCK
if (pthread_rwlock_rdlock(lock) != 0)
return 0;
-# else
+#else
if (pthread_mutex_lock(lock) != 0) {
assert(errno != EDEADLK && errno != EBUSY);
return 0;
}
-# endif
+#endif
return 1;
}
__owur int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
{
-# ifdef USE_RWLOCK
+#ifdef USE_RWLOCK
if (pthread_rwlock_wrlock(lock) != 0)
return 0;
-# else
+#else
if (pthread_mutex_lock(lock) != 0) {
assert(errno != EDEADLK && errno != EBUSY);
return 0;
}
-# endif
+#endif
return 1;
}
int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
{
-# ifdef USE_RWLOCK
+#ifdef USE_RWLOCK
if (pthread_rwlock_unlock(lock) != 0)
return 0;
-# else
+#else
if (pthread_mutex_unlock(lock) != 0) {
assert(errno != EPERM);
return 0;
}
-# endif
+#endif
return 1;
}
@@ -145,11 +145,11 @@ void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock)
if (lock == NULL)
return;
-# ifdef USE_RWLOCK
+#ifdef USE_RWLOCK
pthread_rwlock_destroy(lock);
-# else
+#else
pthread_mutex_destroy(lock);
-# endif
+#endif
OPENSSL_free(lock);
return;
@@ -204,23 +204,23 @@ int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
{
-# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
+#if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
if (__atomic_is_lock_free(sizeof(*val), val)) {
*ret = __atomic_add_fetch(val, amount, __ATOMIC_ACQ_REL);
return 1;
}
-# elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
+#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
+#endif
if (lock == NULL || !CRYPTO_THREAD_write_lock(lock))
return 0;
*val += amount;
- *ret = *val;
+ *ret = *val;
if (!CRYPTO_THREAD_unlock(lock))
return 0;
@@ -229,24 +229,24 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
}
int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret,
- CRYPTO_RWLOCK *lock)
+ CRYPTO_RWLOCK *lock)
{
-# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
+#if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
if (__atomic_is_lock_free(sizeof(*val), val)) {
*ret = __atomic_or_fetch(val, op, __ATOMIC_ACQ_REL);
return 1;
}
-# elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
+#elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
/* This will work for all future Solaris versions. */
if (ret != NULL) {
*ret = atomic_or_64_nv(val, op);
return 1;
}
-# endif
+#endif
if (lock == NULL || !CRYPTO_THREAD_write_lock(lock))
return 0;
*val |= op;
- *ret = *val;
+ *ret = *val;
if (!CRYPTO_THREAD_unlock(lock))
return 0;
@@ -256,32 +256,32 @@ int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret,
int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock)
{
-# if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
+#if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
if (__atomic_is_lock_free(sizeof(*val), val)) {
__atomic_load(val, ret, __ATOMIC_ACQUIRE);
return 1;
}
-# elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
+#elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
/* This will work for all future Solaris versions. */
if (ret != NULL) {
*ret = atomic_or_64_nv(val, 0);
return 1;
}
-# endif
+#endif
if (lock == NULL || !CRYPTO_THREAD_read_lock(lock))
return 0;
- *ret = *val;
+ *ret = *val;
if (!CRYPTO_THREAD_unlock(lock))
return 0;
return 1;
}
-# ifndef FIPS_MODULE
+#ifndef FIPS_MODULE
int openssl_init_fork_handlers(void)
{
return 1;
}
-# endif /* FIPS_MODULE */
+#endif /* FIPS_MODULE */
int openssl_get_fork_id(void)
{