Skip to content

Commit

Permalink
For thread-debug builds, use error-checking mutexes for proc_mutex_pt…
Browse files Browse the repository at this point in the history
…hread:

* 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


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1918259 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Jun 11, 2024
1 parent e395624 commit 8344a64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions locks/unix/proc_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,18 @@ static apr_status_t proc_mutex_pthread_create(apr_proc_mutex_t *new_mutex,
}
#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;
Expand Down
14 changes: 14 additions & 0 deletions test/testprocmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ static void test_exclusive(abts_case *tc, const char *lockname,

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);
Expand Down

0 comments on commit 8344a64

Please sign in to comment.