From ca3402074ca87dae7890ef1a5bba3865acc83124 Mon Sep 17 00:00:00 2001 From: ranoongs Date: Mon, 29 Jul 2024 00:16:50 +0900 Subject: [PATCH] Edited mutex lock of dlt_housekeeper_running_mutex. The original place of mutex lock was wrong because it didn't protect dlt_housekeeper_running and there was no mutex lock when sending signal. --- src/lib/dlt_user.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 6591b93c4..707bb4ea8 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -3827,6 +3827,9 @@ void dlt_user_housekeeperthread_function(void *ptr) pthread_cleanup_push(dlt_user_cleanup_handler, NULL); + + pthread_mutex_lock(&dlt_housekeeper_running_mutex); + // signal dlt thread to be running *dlt_housekeeper_running = true; signal_status = pthread_cond_signal(&dlt_housekeeper_running_cond); @@ -3834,6 +3837,8 @@ void dlt_user_housekeeperthread_function(void *ptr) dlt_log(LOG_CRIT, "Housekeeper thread failed to signal running state\n"); } + pthread_mutex_unlock(&dlt_housekeeper_running_mutex); + while (in_loop) { /* Check for new messages from DLT daemon */ if (!dlt_user.disable_injection_msg) @@ -5052,6 +5057,10 @@ int dlt_start_threads() * (spurious wakeup) * To protect against this, a while loop with a timeout is added * */ + + // pthread_cond_timedwait has to be called on a locked mutex + pthread_mutex_lock(&dlt_housekeeper_running_mutex); + while (!dlt_housekeeper_running && now.tv_sec <= time_to_wait.tv_sec) { @@ -5064,13 +5073,10 @@ int dlt_start_threads() single_wait.tv_sec = now.tv_sec; single_wait.tv_nsec = now.tv_nsec + 500000000; - // pthread_cond_timedwait has to be called on a locked mutex - pthread_mutex_lock(&dlt_housekeeper_running_mutex); signal_status = pthread_cond_timedwait( &dlt_housekeeper_running_cond, &dlt_housekeeper_running_mutex, &single_wait); - pthread_mutex_unlock(&dlt_housekeeper_running_mutex); /* otherwise it might be a spurious wakeup, try again until the time is over */ if (signal_status == 0) { @@ -5078,6 +5084,8 @@ int dlt_start_threads() } } + pthread_mutex_unlock(&dlt_housekeeper_running_mutex); + if (signal_status != 0 && !dlt_housekeeper_running) { dlt_log(LOG_CRIT, "Failed to wait for house keeper thread!\n"); dlt_stop_threads();