From cf50fb941e98f40280c73c23ee1bce39472af658 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 9d8fe0058d8..2f428911744 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,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 137e70e5bf8..da4baefb83d 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 ed082088057..46beb891ed6 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -301,6 +301,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.39.5