From 71c3b5de38a1073f0ef6d0b95fff386cf3af3173 Mon Sep 17 00:00:00 2001 From: Hanno Schwalm Date: Sat, 14 Dec 2024 07:37:42 +0100 Subject: [PATCH] Add flags for finalized job threads Report non-finalized threads in logs --- src/control/control.c | 10 ++++++++++ src/control/control.h | 3 +++ src/control/jobs.c | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/control/control.c b/src/control/control.c index 064820e5df35..a462aca770ee 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -350,6 +350,16 @@ void dt_control_shutdown(dt_control_t *control) dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] gphoto thread joined"); #endif + // report not-finalized threads + if(!control->kicker_finalized) + dt_print(DT_DEBUG_CONTROL, "kicker thread not finalized"); + for(int k = 0; k < control->num_threads-1; k++) + if(!control->finalized[k]) + dt_print(DT_DEBUG_CONTROL, "num thread %d not finalized", k); + for(int k = 0; k < DT_CTL_WORKER_RESERVED; k++) + if(!control->finalized_res[k]) + dt_print(DT_DEBUG_CONTROL, "reserved thread %d not finalized", k); + /* wait for kick_on_workers_thread */ err = pthread_join(control->kick_on_workers_thread, NULL); dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] joined kicker%s", err ? ", error" : ""); diff --git a/src/control/control.h b/src/control/control.h index 64a83fab6fec..67c152511f97 100644 --- a/src/control/control.h +++ b/src/control/control.h @@ -194,6 +194,8 @@ typedef struct dt_control_t pthread_cond_t cond; int32_t num_threads; pthread_t *thread, kick_on_workers_thread, update_gphoto_thread; + uint8_t *finalized; + uint8_t kicker_finalized; dt_job_t **job; GList *queues[DT_JOB_QUEUE_MAX]; @@ -202,6 +204,7 @@ typedef struct dt_control_t dt_pthread_mutex_t res_mutex; dt_job_t *job_res[DT_CTL_WORKER_RESERVED]; uint8_t new_res[DT_CTL_WORKER_RESERVED]; + uint8_t finalized_res[DT_CTL_WORKER_RESERVED]; pthread_t thread_res[DT_CTL_WORKER_RESERVED]; struct diff --git a/src/control/jobs.c b/src/control/jobs.c index 488ef93e5503..05cd0d07fbbc 100644 --- a/src/control/jobs.c +++ b/src/control/jobs.c @@ -525,6 +525,7 @@ static void *_control_work_res(void *ptr) pthread_setcancelstate(old, &tmp); } } + control->finalized_res[threadid] = 1; return NULL; } @@ -539,6 +540,7 @@ static void *_control_worker_kicker(void *ptr) pthread_cond_broadcast(&control->cond); dt_pthread_mutex_unlock(&control->cond_mutex); } + control->kicker_finalized = 1; return NULL; } @@ -565,6 +567,7 @@ static void *_control_work(void *ptr) dt_pthread_mutex_unlock(&control->cond_mutex); } } + control->finalized[threadid] = 1; return NULL; } @@ -604,7 +607,8 @@ void dt_control_jobs_init(dt_control_t *control) control->num_threads = dt_worker_threads(); control->thread = (pthread_t *)calloc(control->num_threads, sizeof(pthread_t)); control->job = (dt_job_t **)calloc(control->num_threads, sizeof(dt_job_t *)); - + control->finalized = (uint8_t*)calloc(control->num_threads, sizeof(uint8_t)); + control->kicker_finalized = 0; g_atomic_int_set(&control->running, DT_CONTROL_STATE_RUNNING); int err = 0; // collected errors while creating all threads @@ -615,6 +619,7 @@ void dt_control_jobs_init(dt_control_t *control) params->self = control; params->threadid = k; err |= dt_pthread_create(&control->thread[k], _control_work, params); + control->finalized[k] = 0; } /* create queue kicker thread */ @@ -628,6 +633,7 @@ void dt_control_jobs_init(dt_control_t *control) params->self = control; params->threadid = k; err |= dt_pthread_create(&control->thread_res[k], _control_work_res, params); + control->finalized_res[k] = 0; } /* create thread taking care of connecting gphoto2 devices */ #ifdef HAVE_GPHOTO2 @@ -643,6 +649,8 @@ void dt_control_jobs_cleanup(dt_control_t *control) control->job = NULL; free(control->thread); control->thread = NULL; + free(control->finalized); + control->finalized = NULL; } int dt_control_jobs_pending(dt_control_t *control)