From 3bfb493fa0c61f33ac930320f7b69ce4a96c2eb6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 28 Nov 2017 15:21:55 +0800 Subject: [PATCH] cmake,common/RWLock: check for libpthread extensions pthread_rwlockattr_setkind_np() is a GNU extension of libpthread. and Tianshan Qu pointed out, we cannot use ifdef(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) to detect the availability of this function, because it's an enum not a macro. so, like other *_np() extensions, we check this one also using cmake at the configure phase. Reported-by: Tianshan Qu Signed-off-by: Kefu Chai --- CMakeLists.txt | 1 + src/common/RWLock.h | 3 ++- src/include/config-h.in.cmake | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c358e3e9748..cbd729bf32a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ CHECK_FUNCTION_EXISTS(pthread_spin_init HAVE_PTHREAD_SPINLOCK) CHECK_FUNCTION_EXISTS(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP) CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP) CHECK_FUNCTION_EXISTS(pthread_getname_np HAVE_PTHREAD_GETNAME_NP) +CHECK_FUNCTION_EXISTS(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP) CHECK_FUNCTION_EXISTS(eventfd HAVE_EVENTFD) CHECK_FUNCTION_EXISTS(getprogname HAVE_GETPROGNAME) diff --git a/src/common/RWLock.h b/src/common/RWLock.h index fd8a2665ef1..a1d8c88a30a 100644 --- a/src/common/RWLock.h +++ b/src/common/RWLock.h @@ -20,6 +20,7 @@ #include #include #include +#include "acconfig.h" #include "lockdep.h" #include "common/valgrind.h" @@ -42,7 +43,7 @@ public: RWLock(const std::string &n, bool track_lock=true, bool ld=true, bool prioritize_write=false) : name(n), id(-1), track(track_lock), lockdep(ld) { -#if defined(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) +#if defined(HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP) if (prioritize_write) { pthread_rwlockattr_t attr; pthread_rwlockattr_init(&attr); diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index 2847ceea2a8..71ad9e6386f 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -298,6 +298,9 @@ /* Defined if pthread_setname_np() is available */ #cmakedefine HAVE_PTHREAD_SETNAME_NP 1 +/* Defined if pthread_rwlockattr_setkind_np() is available */ +#cmakedefine HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP + /* Defined if blkin enabled */ #cmakedefine WITH_BLKIN -- 2.47.3