Commit a4c4a01a authored by Andreas Schuh's avatar Andreas Schuh

Check if pthread_rwlock_t is available and use it if so.

parent 8477f317
...@@ -60,11 +60,13 @@ endif () ...@@ -60,11 +60,13 @@ endif ()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# system checks # 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)") 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) mark_as_advanced(GFLAGS_INTTYPES_FORMAT)
if (NOT GFLAGS_INTTYPES_FORMAT) if (NOT GFLAGS_INTTYPES_FORMAT)
include (CheckTypeSize)
foreach (type IN ITEMS uint32_t u_int32_t __int32) foreach (type IN ITEMS uint32_t u_int32_t __int32)
check_type_size (${type} SIZE LANGUAGE CXX) check_type_size (${type} SIZE LANGUAGE CXX)
if (SIZE) if (SIZE)
...@@ -87,17 +89,14 @@ if (NOT GFLAGS_INTTYPES_FORMAT) ...@@ -87,17 +89,14 @@ if (NOT GFLAGS_INTTYPES_FORMAT)
" Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.") " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
endif () endif ()
endif () endif ()
set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" TRUE) set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" TRUE)
include (CheckIncludeFileCXX)
foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat) foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat)
string (TOUPPER "${fname}" FNAME) string (TOUPPER "${fname}" FNAME)
string (REGEX REPLACE "/" "_" FNAME "${FNAME}") string (REGEX REPLACE "/" "_" FNAME "${FNAME}")
check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H) check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H)
endforeach () endforeach ()
include (CheckCxxSymbolExists)
foreach (fname IN ITEMS strtoll strtoq) foreach (fname IN ITEMS strtoll strtoq)
string (TOUPPER "${fname}" FNAME) string (TOUPPER "${fname}" FNAME)
check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME}) check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME})
...@@ -107,6 +106,7 @@ set (CMAKE_THREAD_PREFER_PTHREAD TRUE) ...@@ -107,6 +106,7 @@ set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package (ThreadsCxx) find_package (ThreadsCxx)
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
set (GFLAGS_HAVE_PTHREAD TRUE) set (GFLAGS_HAVE_PTHREAD TRUE)
check_type_size (pthread_rwlock_t GFLAGS_HAVE_RWLOCK LANGUAGE CXX)
else () else ()
set (GFLAGS_HAVE_PTHREAD FALSE) set (GFLAGS_HAVE_PTHREAD FALSE)
endif () endif ()
......
...@@ -126,6 +126,9 @@ ...@@ -126,6 +126,9 @@
// Define if you have the <pthread.h> header file. // Define if you have the <pthread.h> header file.
#cmakedefine GFLAGS_HAVE_PTHREAD #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 // Backwards compatibility in case users defined these macros themselves
// or allow users to use these more general macros if the gflags library // 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 // is build as part of a user project, e.g., included as Git submodule
......
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
typedef CRITICAL_SECTION MutexType; typedef CRITICAL_SECTION MutexType;
#elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK) #elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK)
// Needed for pthread_rwlock_*. If it causes problems, you could take it // 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 // *does* cause problems for FreeBSD, or MacOSX, but isn't needed
// for locking there.) // for locking there.)
# ifdef __linux__ # ifdef __linux__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment