Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,34 @@ add_compile_options(
-Wcast-qual
-Wno-system-headers
-Wno-unused-function
-Wno-stringop-truncation
$<$<C_COMPILER_ID:GNU>:-Wno-stringop-truncation>
)

if(APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang")
# Clang on macOS is stricter than GCC on some warnings that are promoted to
# errors by -Werror above. Suppress the ones triggered by current code until
# the upstream sources are fixed. Probe each flag so older Clang versions
# (or a non-Clang compiler explicitly selected on macOS) don't fail the
# build with "unknown warning option" turned into an error.
include(CheckCCompilerFlag)
foreach(_dlt_clang_flag
-Wno-sign-conversion
-Wno-implicit-int-conversion
-Wno-shorten-64-to-32
-Wno-strict-prototypes
-Wno-static-in-inline
-Wno-gnu-folding-constant
-Wno-gnu-zero-variadic-macro-arguments
-Wno-variadic-macro-arguments-omitted
-Wno-deprecated-declarations)
string(MAKE_C_IDENTIFIER "HAVE_CFLAG_${_dlt_clang_flag}" _dlt_have_var)
check_c_compiler_flag("${_dlt_clang_flag}" ${_dlt_have_var})
if(${_dlt_have_var})
add_compile_options($<$<COMPILE_LANGUAGE:C>:${_dlt_clang_flag}>)
endif()
Comment thread
felipek marked this conversation as resolved.
endforeach()
endif()

if(WITH_DOC STREQUAL "OFF")
set(PACKAGE_DOC "#")
else()
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN|MSYS")
set(RT_LIBRARY rt)
set(SOCKET_LIBRARY "")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(RT_LIBRARY "")
set(SOCKET_LIBRARY "")
else()
set(RT_LIBRARY "")
set(SOCKET_LIBRARY socket)
Expand Down
4 changes: 3 additions & 1 deletion src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,9 @@ static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
{
int ret;
int fd = -1;
#ifdef __linux__
int fifo_size;
#endif

/* open named pipe(FIFO) to receive DLT messages from users */
umask(0);
Expand Down Expand Up @@ -5703,7 +5705,7 @@ int create_timer_fd(DltDaemonLocal *daemon_local,
timer_name, strerror(errno));
local_fd = DLT_FD_INIT;
}
#elif __QNX__
#elif defined(__QNX__)
/*
* Since timerfd is not valid in QNX, new threads are introduced
* to manage timers and communicate with main thread when timer expires.
Expand Down
3 changes: 3 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ add_library(dlt ${dlt_LIB_SRCS})
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN|MSYS")
set(RT_LIBRARY rt)
set(SOCKET_LIBRARY "")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(RT_LIBRARY "")
set(SOCKET_LIBRARY "")
else()
set(RT_LIBRARY "")
set(SOCKET_LIBRARY socket)
Expand Down
35 changes: 31 additions & 4 deletions src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -3949,7 +3949,11 @@ void *dlt_user_trace_network_segmented_thread(void *unused)
/* Unused on purpose. */
(void)unused;
#ifdef DLT_USE_PTHREAD_SETNAME_NP
#ifdef __APPLE__
if (pthread_setname_np("dlt_segmented"))
#else
if (pthread_setname_np(dlt_user.dlt_segmented_nwt_handle, "dlt_segmented"))
#endif
dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n");
#elif linux
if (prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0) < 0)
Expand Down Expand Up @@ -4835,7 +4839,11 @@ void *dlt_user_housekeeperthread_function(void *ptr)
#endif

#ifdef DLT_USE_PTHREAD_SETNAME_NP
#ifdef __APPLE__
if (pthread_setname_np("dlt_housekeeper"))
#else
if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper"))
#endif
dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n");
#elif linux
if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0)
Expand Down Expand Up @@ -7349,6 +7357,18 @@ void dlt_user_test_corrupt_message_size(int enable, int16_t size)
#endif


/*
* Clock used to derive deadlines for pthread_cond_timedwait(). On macOS that
* function always uses CLOCK_REALTIME (pthread_condattr_setclock() is not
* available), so the deadline has to be built from CLOCK_REALTIME or the
* timed wait can return immediately or block far longer than intended.
*/
#ifdef __APPLE__
# define DLT_COND_TIMEDWAIT_CLOCK CLOCK_REALTIME
#else
# define DLT_COND_TIMEDWAIT_CLOCK CLOCK_MONOTONIC
#endif

int dlt_start_threads()
{
struct timespec time_to_wait, single_wait;
Expand All @@ -7357,12 +7377,19 @@ int dlt_start_threads()
atomic_bool dlt_housekeeper_running = false;

/*
* Configure the condition varibale to use CLOCK_MONOTONIC.
* This makes sure we're protected against changes in the system clock
* Configure the condition variable to use CLOCK_MONOTONIC on platforms
* that support pthread_condattr_setclock(). This protects timed waits
* against changes in the system clock.
* On macOS, pthread_condattr_setclock() is unavailable and
* pthread_cond_timedwait() always uses CLOCK_REALTIME, so both the
* condition variable behavior and the deadline calculation must use
* CLOCK_REALTIME there (see DLT_COND_TIMEDWAIT_CLOCK).
*/
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),
Expand All @@ -7373,7 +7400,7 @@ int dlt_start_threads()
return -1;
}

clock_gettime(CLOCK_MONOTONIC, &now);
clock_gettime(DLT_COND_TIMEDWAIT_CLOCK, &now);
/* wait at most 10s */
time_to_wait.tv_sec = now.tv_sec + 10;
time_to_wait.tv_nsec = now.tv_nsec;
Expand All @@ -7399,7 +7426,7 @@ int dlt_start_threads()
* this makes sure we don't block too long
* even if we missed the signal
*/
clock_gettime(CLOCK_MONOTONIC, &now);
clock_gettime(DLT_COND_TIMEDWAIT_CLOCK, &now);
if (now.tv_nsec >= 500000000) {
single_wait.tv_sec = now.tv_sec + 1;
single_wait.tv_nsec = now.tv_nsec - 500000000;
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading