From a39005253b58c1ce7e8ae675ce4435d2e8961834 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Fri, 28 Jan 2022 12:44:21 +0800 Subject: [PATCH] check pthread_rwlockattr_getkind_np for porting --- INSTALL | 2 +- make.sh | 23 +++++++++++++++++++++-- src/pthread_func.c | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/INSTALL b/INSTALL index f042cd4..926401f 100644 --- a/INSTALL +++ b/INSTALL @@ -12,6 +12,6 @@ Chinese language: http://www.fastken.com/ # the command lines as: git clone https://github.com/happyfish100/libfastcommon.git - cd libfastcommon; git checkout V1.0.48 + cd libfastcommon; git checkout V1.0.55 ./make.sh clean && ./make.sh && ./make.sh install diff --git a/make.sh b/make.sh index 616705b..a145c0b 100755 --- a/make.sh +++ b/make.sh @@ -138,10 +138,29 @@ cat < src/_os_define.h #endif EOF -if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then +pthread_path='' +for path in /lib /lib64 /usr/lib /usr/lib64 /usr/local/lib; do + if [ -d $path ]; then + pthread_path=$(find $path -name libpthread.so | head -n 1) + if [ -n "$pthread_path" ]; then + break + fi + + pthread_path=$(find $path -name libpthread.a | head -n 1) + if [ -n "$pthread_path" ]; then + break + fi + fi +done + +if [ -n "$pthread_path" ]; then LIBS="$LIBS -lpthread" + line=$(nm $pthread_path | fgrep pthread_rwlockattr_getkind_np | fgrep -w T) + if [ -n "$line" ]; then + CFLAGS="$CFLAGS -DWITH_PTHREAD_RWLOCKATTR_GETKIND_NP=1" + fi elif [ -f /usr/lib/libc_r.so ]; then - line=`nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T` + line=$(nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T) if [ -n "$line" ]; then LIBS="$LIBS -lc_r" fi diff --git a/src/pthread_func.c b/src/pthread_func.c index 8ba9c21..864aa93 100644 --- a/src/pthread_func.c +++ b/src/pthread_func.c @@ -80,7 +80,7 @@ int init_pthread_rwlock(pthread_rwlock_t *rwlock) int result; -#ifdef OS_LINUX +#ifdef WITH_PTHREAD_RWLOCKATTR_GETKIND_NP attr.ptr = &attr.holder; if ((result=pthread_rwlockattr_init(attr.ptr)) != 0) { logError("file: "__FILE__", line: %d, "