Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From d64a282b57352dde5f5b007947c005e504dc9a6b Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sat, 17 Dec 2022 10:46:31 -0800 |
| 4 | Subject: [PATCH] configure: Check for pthread_rwlockattr_setkind_np before use |
| 5 | |
| 6 | musl does not implement this therefore detect this non-posix API before |
| 7 | using it |
| 8 | |
| 9 | Upstream-Status: Submitted [https://github.com/stressapptest/stressapptest/pull/100] |
| 10 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 11 | --- |
| 12 | configure.ac | 1 + |
| 13 | src/worker.cc | 2 ++ |
| 14 | 2 files changed, 3 insertions(+) |
| 15 | |
| 16 | diff --git a/configure.ac b/configure.ac |
| 17 | index 403728c..47968cb 100644 |
| 18 | --- a/configure.ac |
| 19 | +++ b/configure.ac |
| 20 | @@ -157,6 +157,7 @@ AC_FUNC_STRERROR_R |
| 21 | AC_FUNC_VPRINTF |
| 22 | AC_CHECK_FUNCS([ftruncate gettimeofday memset munmap select socket strtol strtoull]) |
| 23 | AC_CHECK_FUNCS([mmap64 posix_memalign rand_r sched_getaffinity]) |
| 24 | +AC_CHECK_FUNCS([pthread_rwlockattr_setkind_np]) |
| 25 | |
| 26 | AC_CONFIG_FILES([Makefile src/Makefile]) |
| 27 | AC_OUTPUT |
| 28 | diff --git a/src/worker.cc b/src/worker.cc |
| 29 | index 41e93a0..c4abc87 100644 |
| 30 | --- a/src/worker.cc |
| 31 | +++ b/src/worker.cc |
| 32 | @@ -133,9 +133,11 @@ void WorkerStatus::Initialize() { |
| 33 | |
| 34 | pthread_rwlockattr_t attrs; |
| 35 | sat_assert(0 == pthread_rwlockattr_init(&attrs)); |
| 36 | +#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP |
| 37 | // Avoid writer lock starvation. |
| 38 | sat_assert(0 == pthread_rwlockattr_setkind_np( |
| 39 | &attrs, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP)); |
| 40 | +#endif |
| 41 | sat_assert(0 == pthread_rwlock_init(&status_rwlock_, &attrs)); |
| 42 | |
| 43 | #ifdef HAVE_PTHREAD_BARRIERS |