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 2024/06/11 16:07:16 UTC

svn commit: r1918259 - in /apr/apr/trunk: .github/workflows/linux.yml locks/unix/proc_mutex.c test/testprocmutex.c

Author: jorton
Date: Tue Jun 11 16:07:15 2024
New Revision: 1918259

URL: http://svn.apache.org/viewvc?rev=1918259&view=rev
Log:
For thread-debug builds, use error-checking mutexes for proc_mutex_pthread:

* locks/unix/proc_mutex.c (proc_mutex_pthread_create):
  [APR_THREAD_DEBUG]: Set the mutex type to ERRORCHECK.

* test/testprocmutex.c (test_exclusive): Skip the trylock/timedlock
  tests for thread-debug builds since it triggers undefined behaviour
  with proc_pthread mutexes.

CI: Add a --enable-thread-debug job.

Github: closes #57

Modified:
    apr/apr/trunk/.github/workflows/linux.yml
    apr/apr/trunk/locks/unix/proc_mutex.c
    apr/apr/trunk/test/testprocmutex.c

Modified: apr/apr/trunk/.github/workflows/linux.yml
URL: http://svn.apache.org/viewvc/apr/apr/trunk/.github/workflows/linux.yml?rev=1918259&r1=1918258&r2=1918259&view=diff
==============================================================================
--- apr/apr/trunk/.github/workflows/linux.yml (original)
+++ apr/apr/trunk/.github/workflows/linux.yml Tue Jun 11 16:07:15 2024
@@ -25,6 +25,8 @@ jobs:
             config: --enable-pool-debug
           - name: Pool-debug, maintainer-mode
             config: --enable-pool-debug --enable-maintainer-mode
+          - name: Thread-debug, maintainer-mode
+            config: --enable-thread-debug --enable-maintainer-mode
           - name: Maintainer-mode, no IPv6
             config: --enable-maintainer-mode --disable-ipv6
           - name: Maintainer-mode, -Werror

Modified: apr/apr/trunk/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=1918259&r1=1918258&r2=1918259&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/proc_mutex.c (original)
+++ apr/apr/trunk/locks/unix/proc_mutex.c Tue Jun 11 16:07:15 2024
@@ -646,6 +646,18 @@ static apr_status_t proc_mutex_pthread_c
     }
 #endif /* HAVE_PTHREAD_MUTEX_ROBUST[_NP] */
 
+#if defined(APR_THREAD_DEBUG)
+    /* ignore errors. */
+    if ((rv = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ERRORCHECK))) {
+#ifdef HAVE_ZOS_PTHREADS
+        rv = errno;
+#endif
+        proc_mutex_pthread_cleanup(new_mutex);
+        pthread_mutexattr_destroy(&mattr);
+        return rv;
+    }
+#endif
+
     if ((rv = pthread_mutex_init(&proc_pthread_mutex(new_mutex), &mattr))) {
 #ifdef HAVE_ZOS_PTHREADS
         rv = errno;

Modified: apr/apr/trunk/test/testprocmutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testprocmutex.c?rev=1918259&r1=1918258&r2=1918259&view=diff
==============================================================================
--- apr/apr/trunk/test/testprocmutex.c (original)
+++ apr/apr/trunk/test/testprocmutex.c Tue Jun 11 16:07:15 2024
@@ -141,6 +141,20 @@ static void test_exclusive(abts_case *tc
 
     ABTS_ASSERT(tc, "Locks don't appear to work", *x == MAX_COUNTER);
 
+#if defined(APR_THREAD_DEBUG)
+    /* The following tests attempt to (try-)lock a mutex which is
+     * already held by the process. This is undefined behaviour for a
+     * pthreads mutex, and with the ERRORCHECK mutex type enabled for
+     * APR_THREAD_DEBUG, fails with EDEADLOCK. (These tests may fail
+     * for other pthreads implementations as well) */
+    if (mech->num == APR_LOCK_PROC_PTHREAD
+        || ((mech->num == APR_LOCK_DEFAULT || mech->num == APR_LOCK_DEFAULT_TIMED)
+            && APR_USE_PROC_PTHREAD_SERIALIZE)) {
+        fprintf(stderr, "skipping trylock tests for %s\n", mech->name);
+        return;
+    }
+#endif
+
     rv = apr_proc_mutex_trylock(proc_lock);
     if (rv == APR_ENOTIMPL) {
         fprintf(stderr, "%s_trylock() not implemented, ", mech->name);