summaryrefslogtreecommitdiffstats
path: root/crypto/threads_pthread.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2021-01-21 12:32:27 -0500
committerMatt Caswell <matt@openssl.org>2021-02-05 10:29:44 +0000
commite60147fe74c202ef3ce5d36115252b7c3c504cd7 (patch)
tree7ff469c2db1895205e12b21da7a4a446d6462bd7 /crypto/threads_pthread.c
parent05f41859ddfff9b19f6599e545607f3d49630ce0 (diff)
Don't make pthreads mutexes recursive.
Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13924)
Diffstat (limited to 'crypto/threads_pthread.c')
-rw-r--r--crypto/threads_pthread.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index 22ba793161..68ec5dc1df 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -51,12 +51,15 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
return NULL;
}
+ /*
+ * We don't use recursive mutexes, but try to catch errors if we do.
+ */
pthread_mutexattr_init(&attr);
- #if defined(__TANDEM) && defined(_SPT_MODEL_)
- pthread_mutexattr_setkind_np(&attr,MUTEX_RECURSIVE_NP);
- #else
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- #endif
+# if defined(NDEBUG) && defined(PTHREAD_MUTEX_ERRORCHECK)
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+# else
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
+# endif
if (pthread_mutex_init(lock, &attr) != 0) {
pthread_mutexattr_destroy(&attr);
@@ -76,8 +79,10 @@ int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
if (pthread_rwlock_rdlock(lock) != 0)
return 0;
# else
- if (pthread_mutex_lock(lock) != 0)
+ if (pthread_mutex_lock(lock) != 0) {
+ assert(errno != EDEADLK && errno != EBUSY);
return 0;
+ }
# endif
return 1;
@@ -89,8 +94,10 @@ int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
if (pthread_rwlock_wrlock(lock) != 0)
return 0;
# else
- if (pthread_mutex_lock(lock) != 0)
+ if (pthread_mutex_lock(lock) != 0) {
+ assert(errno != EDEADLK && errno != EBUSY);
return 0;
+ }
# endif
return 1;
@@ -102,8 +109,10 @@ int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
if (pthread_rwlock_unlock(lock) != 0)
return 0;
# else
- if (pthread_mutex_unlock(lock) != 0)
+ if (pthread_mutex_unlock(lock) != 0) {
+ assert(errno != EPERM);
return 0;
+ }
# endif
return 1;