From d64a282b57352dde5f5b007947c005e504dc9a6b Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 17 Dec 2022 10:46:31 -0800
Subject: [PATCH] configure: Check for pthread_rwlockattr_setkind_np before use

musl does not implement this therefore detect this non-posix API before
using it

Upstream-Status: Submitted [https://github.com/stressapptest/stressapptest/pull/100]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 configure.ac  | 1 +
 src/worker.cc | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/configure.ac b/configure.ac
index 403728c..47968cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,6 +157,7 @@ AC_FUNC_STRERROR_R
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([ftruncate gettimeofday memset munmap select socket strtol strtoull])
 AC_CHECK_FUNCS([mmap64 posix_memalign rand_r sched_getaffinity])
+AC_CHECK_FUNCS([pthread_rwlockattr_setkind_np])
 
 AC_CONFIG_FILES([Makefile src/Makefile])
 AC_OUTPUT
diff --git a/src/worker.cc b/src/worker.cc
index 41e93a0..c4abc87 100644
--- a/src/worker.cc
+++ b/src/worker.cc
@@ -133,9 +133,11 @@ void WorkerStatus::Initialize() {
 
   pthread_rwlockattr_t attrs;
   sat_assert(0 == pthread_rwlockattr_init(&attrs));
+#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
   // Avoid writer lock starvation.
   sat_assert(0 == pthread_rwlockattr_setkind_np(
                       &attrs, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP));
+#endif
   sat_assert(0 == pthread_rwlock_init(&status_rwlock_, &attrs));
 
 #ifdef HAVE_PTHREAD_BARRIERS
