This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 823ca8cfb8 Cleanup ink_thread.h of wrong BSD checks assuming missing 
pthread functions (#10863)
823ca8cfb8 is described below

commit 823ca8cfb8d7f870fb36c52b7448ce887008cb9a
Author: Phong Nguyen <[email protected]>
AuthorDate: Fri Feb 9 08:34:38 2024 -0800

    Cleanup ink_thread.h of wrong BSD checks assuming missing pthread functions 
(#10863)
    
    Commit 26c4080 attempted to replace some FreeBSD pthread function checks 
with function checking. This was reverted in 012df52 as feature detection 
should be done via autoconf (or now, CMake).
    
    However, every remotely recent version of FreeBSD has the pthread functions 
in question. There seems to be no reason to bother to check for pthread_cancel 
or pthread_getschedparam.
    
    In doing this, this allows us to remove HAVE_SYS_CAPABILITY_H and 
HAVE_SYS_PRCTL_H, replacing them with __has_include directives. We also 
introduce a direct HAVE_PRCTL feature check to replace the implied existence of 
it in HAVE_SYS_PRCTL_H.
    
    In addition, the merge of #10823 into #11029 dropped a fix in which 
HAVE_PTHREAD_MUTEXATTR_SETTYPE was removed but not what called it. 
pthread_mutexattr_settype is available on every modern operating system 
supporting pthread; we should no longer need to check for its existence.
---
 CMakeLists.txt                       |  7 +------
 include/tscore/ink_config.h.cmake.in |  3 +--
 include/tscore/ink_platform.h        |  2 +-
 include/tscore/ink_thread.h          | 22 ++++++----------------
 src/tscore/ink_memory.cc             |  2 +-
 src/tscore/ink_mutex.cc              |  2 +-
 src/tsutil/DbgCtl.cc                 |  2 +-
 7 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 920d15835e..1df645499d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -246,12 +246,6 @@ if(brotli_FOUND)
   set(HAVE_BROTLI_ENCODE_H TRUE)
 endif()
 
-if(TS_USE_POSIX_CAP)
-  # These headers must have been found for capabilites to be enabled.
-  set(HAVE_SYS_CAPABILITY_H TRUE)
-  set(HAVE_SYS_PRCTL_H TRUE)
-endif()
-
 find_package(LibLZMA)
 if(LibLZMA_FOUND)
   set(HAVE_LZMA_H TRUE)
@@ -393,6 +387,7 @@ check_symbol_exists(strlcat string.h HAVE_STRLCAT)
 check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
 check_symbol_exists(strsignal string.h HAVE_STRSIGNAL)
 check_symbol_exists(sysinfo sys/sysinfo.h HAVE_SYSINFO)
+check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL)
 if(TS_USE_HWLOC)
   check_source_compiles(
     C "#include <hwloc.h>
diff --git a/include/tscore/ink_config.h.cmake.in 
b/include/tscore/ink_config.h.cmake.in
index 75bb370473..5e33ca19de 100644
--- a/include/tscore/ink_config.h.cmake.in
+++ b/include/tscore/ink_config.h.cmake.in
@@ -41,8 +41,6 @@
 #cmakedefine HAVE_LZMA_H 1
 #cmakedefine HAVE_IFADDRS_H 1
 #cmakedefine HAVE_LINUX_HDREG_H 1
-#cmakedefine HAVE_SYS_CAPABILITY_H 1
-#cmakedefine HAVE_SYS_PRCTL_H 1
 #cmakedefine HAVE_MALLOC_USABLE_SIZE 1
 #cmakedefine HAVE_MCHECK_PEDANTIC 1
 #cmakedefine HAVE_POSIX_FADVISE 1
@@ -70,6 +68,7 @@
 #cmakedefine01 HAVE_STRLCPY
 #cmakedefine01 HAVE_STRSIGNAL
 #cmakedefine01 HAVE_SYSINFO
+#cmakedefine01 HAVE_PRCTL
 
 #cmakedefine01 HAVE_HWLOC_OBJ_PU
 
diff --git a/include/tscore/ink_platform.h b/include/tscore/ink_platform.h
index a7e4538ad7..e99d356ee4 100644
--- a/include/tscore/ink_platform.h
+++ b/include/tscore/ink_platform.h
@@ -125,7 +125,7 @@ using in_addr_t = unsigned int;
 #include <sys/sysmacros.h>
 #endif
 
-#ifdef HAVE_SYS_PRCTL_H
+#if __has_include(<sys/prctl.h>)
 #include <sys/prctl.h>
 #endif
 
diff --git a/include/tscore/ink_thread.h b/include/tscore/ink_thread.h
index f5f5743986..d50e5e2c75 100644
--- a/include/tscore/ink_thread.h
+++ b/include/tscore/ink_thread.h
@@ -46,7 +46,7 @@
 #include <pthread_np.h>
 #endif
 
-#if __has_include(<sys/prctl.h>) && defined(PR_SET_NAME)
+#if __has_include(<sys/prctl.h>)
 #include <sys/prctl.h>
 #endif
 
@@ -136,13 +136,8 @@ ink_thread_create(ink_thread *tid, void *(*f)(void *), 
void *a, int detached, si
 static inline void
 ink_thread_cancel(ink_thread who)
 {
-#if defined(freebsd)
-  (void)who;
-  ink_assert(!"not supported");
-#else
   int ret = pthread_cancel(who);
   ink_assert(ret == 0);
-#endif
 }
 
 static inline void *
@@ -171,18 +166,11 @@ ink_thread_null()
 static inline int
 ink_thread_get_priority(ink_thread t, int *priority)
 {
-#if defined(freebsd)
-  (void)t;
-  (void)priority;
-  ink_assert(!"not supported");
-  return -1;
-#else
   int policy;
   struct sched_param param;
   int res   = pthread_getschedparam(t, &policy, &param);
   *priority = param.sched_priority;
   return res;
-#endif
 }
 
 static inline int
@@ -236,7 +224,9 @@ ink_cond_timedwait(ink_cond *cp, ink_mutex *mp, 
ink_timestruc *t)
   while (EINTR == (err = pthread_cond_timedwait(cp, mp, t))) {
     ;
   }
-#if defined(freebsd) || defined(openbsd)
+#ifndef ETIME
+// ink_defs.h aliases ETIME to ETIMEDOUT and this path should never happen
+#warning Unknown ETIME return condition for pthread_cond_timedwait
   ink_assert((err == 0) || (err == ETIMEDOUT));
 #else
   ink_assert((err == 0) || (err == ETIME) || (err == ETIMEDOUT));
@@ -280,7 +270,7 @@ ink_set_thread_name(const char *name ATS_UNUSED)
   pthread_setname_np(pthread_self(), name);
 #elif defined(HAVE_PTHREAD_SET_NAME_NP_2)
   pthread_set_name_np(pthread_self(), name);
-#elif defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
+#elif HAVE_PRCTL && defined(PR_SET_NAME)
   prctl(PR_SET_NAME, name, 0, 0, 0);
 #endif
 }
@@ -292,7 +282,7 @@ ink_get_thread_name(char *name, size_t len)
   pthread_getname_np(pthread_self(), name, len);
 #elif defined(HAVE_PTHREAD_GET_NAME_NP)
   pthread_get_name_np(pthread_self(), name, len);
-#elif defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME)
+#elif HAVE_PRCTL && defined(PR_GET_NAME)
   prctl(PR_GET_NAME, name, 0, 0, 0);
 #else
   snprintf(name, len, "0x%" PRIx64, (uint64_t)ink_thread_self());
diff --git a/src/tscore/ink_memory.cc b/src/tscore/ink_memory.cc
index 94311ea7aa..acff952a92 100644
--- a/src/tscore/ink_memory.cc
+++ b/src/tscore/ink_memory.cc
@@ -33,7 +33,7 @@
 #include <mimalloc-override.h>
 #endif
 
-#if !defined(kfreebsd) && defined(freebsd)
+#if __has_include(<malloc_np.h>)
 #include <malloc_np.h> // for malloc_usable_size
 #endif
 
diff --git a/src/tscore/ink_mutex.cc b/src/tscore/ink_mutex.cc
index 1f8dd3f5a6..ec744ca0be 100644
--- a/src/tscore/ink_mutex.cc
+++ b/src/tscore/ink_mutex.cc
@@ -35,7 +35,7 @@ public:
   x_pthread_mutexattr_t()
   {
     pthread_mutexattr_init(&attr);
-#if DEBUG && HAVE_PTHREAD_MUTEXATTR_SETTYPE
+#if DEBUG
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
 #endif
   }
diff --git a/src/tsutil/DbgCtl.cc b/src/tsutil/DbgCtl.cc
index b60873fdd1..da17985893 100644
--- a/src/tsutil/DbgCtl.cc
+++ b/src/tsutil/DbgCtl.cc
@@ -346,7 +346,7 @@ struct DiagThreadname {
     pthread_getname_np(pthread_self(), name, sizeof(name));
 #elif defined(HAVE_PTHREAD_GET_NAME_NP)
     pthread_get_name_np(pthread_self(), name, sizeof(name));
-#elif defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME)
+#elif defined(HAVE_PRCTL) && defined(PR_GET_NAME)
     prctl(PR_GET_NAME, name, 0, 0, 0);
 #else
     snprintf(name, sizeof(name), "0x%" PRIx64, (uint64_t)pthread_self());

Reply via email to