You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2020/06/01 12:45:14 UTC
svn commit: r1878362 - in /apr/apr/trunk: configure.in
locks/unix/thread_mutex.c
Author: jorton
Date: Mon Jun 1 12:45:13 2020
New Revision: 1878362
URL: http://svn.apache.org/viewvc?rev=1878362&view=rev
Log:
* configure.in: Add --enable-thread-debug, which defines
APR_THREAD_DEBUG.
* locks/unix/thread_mutex.c (apr_thread_mutex_create): For
APR_THREAD_DEBUG, use the ERRORCHECK mutex type by default (if not
nested/recursive), which reliably fails for cases of otherwise
undefined behaviour:
a) relocking a mutex locked by the current thread
b) unlocking a thread locked by another thread
Modified:
apr/apr/trunk/configure.in
apr/apr/trunk/locks/unix/thread_mutex.c
Modified: apr/apr/trunk/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?rev=1878362&r1=1878361&r2=1878362&view=diff
==============================================================================
--- apr/apr/trunk/configure.in (original)
+++ apr/apr/trunk/configure.in Mon Jun 1 12:45:13 2020
@@ -435,6 +435,13 @@ AC_ARG_ENABLE(pool-debug,
fi
])
+AC_ARG_ENABLE(thread-debug,
+ [ --enable-thread-debug Turn on run-time thread debugging tests],
+ [ if test $enableval = yes; then
+ APR_ADDTO(CPPFLAGS, [-DAPR_THREAD_DEBUG=1])
+ fi
+ ])
+
if test "$host" = "i586-pc-beos"; then
AC_ARG_ENABLE(malloc-debug,[ --enable-malloc-debug Switch on malloc_debug for BeOS],
APR_REMOVEFROM(CFLAGS, -O2)
Modified: apr/apr/trunk/locks/unix/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/thread_mutex.c?rev=1878362&r1=1878361&r2=1878362&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/thread_mutex.c (original)
+++ apr/apr/trunk/locks/unix/thread_mutex.c Mon Jun 1 12:45:13 2020
@@ -68,7 +68,26 @@ APR_DECLARE(apr_status_t) apr_thread_mut
pthread_mutexattr_destroy(&mattr);
} else
#endif
+ {
+#if defined(APR_THREAD_DEBUG)
+ pthread_mutexattr_t mattr;
+
+ rv = pthread_mutexattr_init(&mattr);
+ if (rv) return rv;
+
+ rv = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ERRORCHECK);
+ if (rv) {
+ pthread_mutexattr_destroy(&mattr);
+ return rv;
+ }
+
+ rv = pthread_mutex_init(&new_mutex->mutex, &mattr);
+
+ pthread_mutexattr_destroy(&mattr);
+#else
rv = pthread_mutex_init(&new_mutex->mutex, NULL);
+#endif
+ }
if (rv) {
#ifdef HAVE_ZOS_PTHREADS