From 067a9ac204ec921db7adfbbda522661d3d5b9cdb Mon Sep 17 00:00:00 2001 From: windskr <1258359012@qq.com> Date: Sun, 8 Mar 2026 17:02:59 +0800 Subject: [PATCH] [FIX] Add macOS compatibility for thread naming and condition variables - Add __APPLE__ check for pthread_setname_np (macOS uses single-argument version) - Skip pthread_condattr_setclock on macOS (CLOCK_MONOTONIC not supported) - Add Darwin case to tests/CMakeLists.txt to avoid linking socket library Fixes build issues on macOS while maintaining compatibility with Linux and QNX. --- src/lib/dlt_user.c | 7 +++++++ tests/CMakeLists.txt | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 6d0098dbe..1f9cc76dc 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -4835,8 +4835,13 @@ void *dlt_user_housekeeperthread_function(void *ptr) #endif #ifdef DLT_USE_PTHREAD_SETNAME_NP +#ifdef __APPLE__ + if (pthread_setname_np("dlt_housekeeper")) + dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); +#else if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper")) dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); +#endif #elif linux if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0) dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n"); @@ -7362,7 +7367,9 @@ int dlt_start_threads() */ pthread_condattr_t attr; pthread_condattr_init(&attr); +#ifndef __APPLE__ pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); +#endif pthread_cond_init(&dlt_housekeeper_running_cond, &attr); if (pthread_create(&(dlt_housekeeperthread_handle), diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7516b90cf..fe7002536 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,8 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN") set(LIBRARIES "") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "QNX") set(LIBRARIES regex) +elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(LIBRARIES "") else() set(LIBRARIES socket) endif()