From a4c4a01a37e09dfa03d30fcf1aa853fb11971788 Mon Sep 17 00:00:00 2001 From: Andreas Schuh Date: Sat, 15 Mar 2014 14:31:21 +0000 Subject: [PATCH] Check if pthread_rwlock_t is available and use it if so. --- CMakeLists.txt | 10 +++++----- src/gflags_declare.h.in | 3 +++ src/mutex.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c90e5b1..c1c2f2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,11 +60,13 @@ endif () # ---------------------------------------------------------------------------- # system checks +include (CheckTypeSize) +include (CheckIncludeFileCXX) +include (CheckCxxSymbolExists) + set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)") mark_as_advanced(GFLAGS_INTTYPES_FORMAT) - if (NOT GFLAGS_INTTYPES_FORMAT) - include (CheckTypeSize) foreach (type IN ITEMS uint32_t u_int32_t __int32) check_type_size (${type} SIZE LANGUAGE CXX) if (SIZE) @@ -87,17 +89,14 @@ if (NOT GFLAGS_INTTYPES_FORMAT) " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.") endif () endif () - set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" TRUE) -include (CheckIncludeFileCXX) foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat) string (TOUPPER "${fname}" FNAME) string (REGEX REPLACE "/" "_" FNAME "${FNAME}") check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H) endforeach () -include (CheckCxxSymbolExists) foreach (fname IN ITEMS strtoll strtoq) string (TOUPPER "${fname}" FNAME) check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME}) @@ -107,6 +106,7 @@ set (CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package (ThreadsCxx) if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) set (GFLAGS_HAVE_PTHREAD TRUE) + check_type_size (pthread_rwlock_t GFLAGS_HAVE_RWLOCK LANGUAGE CXX) else () set (GFLAGS_HAVE_PTHREAD FALSE) endif () diff --git a/src/gflags_declare.h.in b/src/gflags_declare.h.in index 2a25f1d..99a7c2d 100644 --- a/src/gflags_declare.h.in +++ b/src/gflags_declare.h.in @@ -126,6 +126,9 @@ // Define if you have the header file. #cmakedefine GFLAGS_HAVE_PTHREAD +// Define if your pthread library defines the type pthread_rwlock_t +#cmakedefine GFLAGS_HAVE_RWLOCK + // Backwards compatibility in case users defined these macros themselves // or allow users to use these more general macros if the gflags library // is build as part of a user project, e.g., included as Git submodule diff --git a/src/mutex.h b/src/mutex.h index 3b27f84..ae5319d 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -129,7 +129,7 @@ typedef CRITICAL_SECTION MutexType; #elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK) // Needed for pthread_rwlock_*. If it causes problems, you could take it - // out, but then you'd have to unset GFLAGS_HAVE_RWLOCK (at least on linux -- it + // out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it // *does* cause problems for FreeBSD, or MacOSX, but isn't needed // for locking there.) # ifdef __linux__ -- 2.7.4