]> granicus.if.org Git - libevent/commitdiff
Detect existence of pthread_mutexattr_setprotocol()
authorAzat Khuzhin <azat@libevent.org>
Fri, 28 Aug 2020 22:15:20 +0000 (01:15 +0300)
committerAzat Khuzhin <azat@libevent.org>
Fri, 28 Aug 2020 22:15:20 +0000 (01:15 +0300)
Fixes: #1084
CMakeLists.txt
configure.ac
event-config.h.cmake
evthread_pthread.c
include/event2/thread.h

index 5a29621687906752ccf8a6ad8ce22769f7546baf..014044cb45951f0ca65d0fa22972c97b37a2582c 100644 (file)
@@ -189,9 +189,9 @@ if (EVENT__COVERAGE)
 
     message(STATUS "Setting coverage compiler flags")
 
-    set(CMAKE_REQUIRED_LIBRARIES "--coverage")
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "--coverage")
     add_compiler_flags(-g -O0 --coverage)
-    set(CMAKE_REQUIRED_LIBRARIES "")
+    list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "--coverage")
 endif()
 
 set(GNUC 0)
@@ -340,11 +340,19 @@ endif()
 
 # Winsock.
 if(WIN32)
-    set(CMAKE_REQUIRED_LIBRARIES  ws2_32 shell32 advapi32 bcrypt)
+    list(APPEND CMAKE_REQUIRED_LIBRARIES
+        ws2_32
+        shell32
+        advapi32
+        bcrypt
+    )
     set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h -D_WIN32_WINNT=0x0600)
 endif()
 if (SOLARIS)
-    set(CMAKE_REQUIRED_LIBRARIES socket nsl)
+    list(APPEND CMAKE_REQUIRED_LIBRARIES
+        socket
+        nsl
+    )
 endif()
 
 # Check if _GNU_SOURCE is available.
@@ -433,6 +441,13 @@ if (APPLE)
     )
 endif()
 
+if (NOT EVENT__DISABLE_THREAD_SUPPORT AND NOT WIN32)
+    list(APPEND FILES_TO_CHECK pthread.h)
+    # (Only `CHECK_TYPE_SIZE()' will use `CMAKE_EXTRA_INCLUDE_FILES')
+    list(APPEND CMAKE_EXTRA_INCLUDE_FILES pthread.h)
+endif()
+
+# Fills EVENT_INCLUDES
 foreach(FILE ${FILES_TO_CHECK})
     CHECK_INCLUDE_FILE_CONCAT(${FILE} "EVENT")
 endforeach()
@@ -511,9 +526,30 @@ else()
     endif()
 endif()
 
+if (NOT EVENT__DISABLE_THREAD_SUPPORT)
+    if (WIN32)
+        list(APPEND SRC_CORE evthread_win32.c)
+    else()
+        find_package(Threads REQUIRED)
+        if (NOT CMAKE_USE_PTHREADS_INIT)
+            message(FATAL_ERROR
+                    "Failed to find Pthreads, set EVENT__DISABLE_THREAD_SUPPORT to disable")
+        endif()
+
+        set(EVENT__HAVE_PTHREADS 1)
+        list(APPEND LIB_APPS ${CMAKE_THREAD_LIBS_INIT})
+
+        # for CHECK_SYMBOLS_EXIST()
+        list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+
+        CHECK_TYPE_SIZE(pthread_t EVENT__SIZEOF_PTHREAD_T)
+        list(APPEND SYMBOLS_TO_CHECK pthread_mutexattr_setprotocol)
+    endif()
+endif()
+
 # Add stdio.h for vasprintf
-set(EVENT_INCLUDES ${EVENT_INCLUDES} stdio.h)
-CHECK_SYMBOLS_EXIST("${SYMBOLS_TO_CHECK}" "${EVENT_INCLUDES}" "EVENT")
+list(APPEND CMAKE_EXTRA_INCLUDE_FILES ${EVENT_INCLUDES} stdio.h)
+CHECK_SYMBOLS_EXIST("${SYMBOLS_TO_CHECK}" "${CMAKE_EXTRA_INCLUDE_FILES}" "EVENT")
 unset(SYMBOLS_TO_CHECK)
 set(EVENT__HAVE_EPOLL ${EVENT__HAVE_EPOLL_CREATE})
 if(WIN32 AND NOT CYGWIN)
@@ -545,9 +581,6 @@ if(HAVE_PORT_H AND HAVE_PORT_CREATE)
     set(EVENT__HAVE_EVENT_PORTS 1)
 endif()
 
-# Only `CHECK_TYPE_SIZE()' will use `CMAKE_EXTRA_INCLUDE_FILES'
-set(CMAKE_EXTRA_INCLUDE_FILES ${EVENT_INCLUDES})
-
 CHECK_TYPE_SIZE("struct sockaddr_un" EVENT__HAVE_STRUCT_SOCKADDR_UN)
 CHECK_TYPE_SIZE("uint8_t" EVENT__HAVE_UINT8_T)
 CHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T)
@@ -637,13 +670,6 @@ else()
        set(EVENT__SIZEOF_PID_T EVENT__SIZEOF_PID_T)
 endif()
 
-if (NOT EVENT__DISABLE_THREAD_SUPPORT)
-    if (NOT WIN32)
-        list(APPEND CMAKE_EXTRA_INCLUDE_FILES pthread.h)
-    endif()
-    CHECK_TYPE_SIZE(pthread_t EVENT__SIZEOF_PTHREAD_T)
-endif()
-
 if(EVENT__HAVE_CLOCK_GETTIME)
   set(EVENT__DNS_USE_CPU_CLOCK_FOR_ID 1)
 endif()
@@ -884,21 +910,6 @@ if (NOT EVENT__DISABLE_MBEDTLS)
     list(APPEND LIB_APPS ${MBEDTLS_LIBRARIES})
 endif()
 
-if (NOT EVENT__DISABLE_THREAD_SUPPORT)
-    if (WIN32)
-        list(APPEND SRC_CORE evthread_win32.c)
-    else()
-        find_package(Threads REQUIRED)
-        if (NOT CMAKE_USE_PTHREADS_INIT)
-            message(FATAL_ERROR
-                    "Failed to find Pthreads, set EVENT__DISABLE_THREAD_SUPPORT to disable")
-        endif()
-
-        set(EVENT__HAVE_PTHREADS 1)
-        list(APPEND LIB_APPS ${CMAKE_THREAD_LIBS_INIT})
-    endif()
-endif()
-
 if (NOT EVENT__DISABLE_TESTS)
     # Zlib is only used for testing.
     find_package(ZLIB)
index 2599c225078db33705272d0a387a8eddd773f3db..a143224eb7850e12f254e62652522683bd49fdc1 100644 (file)
@@ -786,6 +786,8 @@ if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
      [AC_INCLUDES_DEFAULT()
       #include <pthread.h> ]
   )
+
+  AC_CHECK_FUNCS([pthread_mutexattr_setprotocol])
 fi
 AM_CONDITIONAL(THREADS, [test "$enable_thread_support" != "no"])
 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
index 1e7adb1c230a19948d833258eff57162d74985da..752e7890f7801ff90a481c7334d83d0ea3c82763 100644 (file)
 /* Define if we have pthreads on this system */
 #cmakedefine EVENT__HAVE_PTHREADS 1
 
+/* Define to 1 if you have the `pthread_mutexattr_setprotocol' function. */
+#cmakedefine EVENT__HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL 1
+
 /* Define to 1 if you have the `putenv' function. */
 #cmakedefine EVENT__HAVE_PUTENV 1
 
index a40f5b02787b7bd83bfa2276dfccb0b5920f6bc4..94e7da958619a79279bf367f4ec57486761f970b 100644 (file)
@@ -190,11 +190,15 @@ evthread_use_pthreads_with_flags(int flags)
                return -1;
 
        if (flags & EVTHREAD_PTHREAD_PRIO_INHERIT) {
+#ifdef EVENT__HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
                /* Set up priority inheritance */
                if (pthread_mutexattr_setprotocol(&attr_default, PTHREAD_PRIO_INHERIT))
                        return -1;
                if (pthread_mutexattr_setprotocol(&attr_recursive, PTHREAD_PRIO_INHERIT))
                        return -1;
+#else
+               return -1;
+#endif
        }
 
        evthread_set_lock_callbacks(&cbs);
index 519b4d30a08962878cb31daeca1f7e9166d0a03c..481a02fe9ec6c08ef2ec48355976c66c0a2db940 100644 (file)
@@ -213,7 +213,8 @@ int evthread_use_windows_threads(void);
 EVENT2_EXPORT_SYMBOL
 int evthread_use_pthreads(void);
 
-/* Enables posix mutex priority inheritance. */
+/* Enables posix mutex priority inheritance
+ * (if pthread_mutexattr_setprotocol() is supported). */
 #define EVTHREAD_PTHREAD_PRIO_INHERIT 0x01
 
 /**