diff --git a/src/common/camera_control.c b/src/common/camera_control.c index 13ad7c5587a1..3d2efed9fb4a 100644 --- a/src/common/camera_control.c +++ b/src/common/camera_control.c @@ -654,7 +654,7 @@ void dt_camctl_camera_stop_live_view(const dt_camctl_t *c) } dt_print(DT_DEBUG_CAMCTL, "[camera_control] Stopping live view"); cam->is_live_viewing = FALSE; - pthread_join(cam->live_view_thread, NULL); + dt_pthread_join(cam->live_view_thread); // tell camera to get back to normal state (close mirror) dt_camctl_camera_set_property_int(camctl, NULL, "eosviewfinder", 0); dt_camctl_camera_set_property_int(camctl, NULL, "viewfinder", 0); diff --git a/src/common/dtpthread.c b/src/common/dtpthread.c index 2420b97fa312..718c76f4455e 100644 --- a/src/common/dtpthread.c +++ b/src/common/dtpthread.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2016-2023 darktable developers. + Copyright (C) 2016-2024 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,8 @@ #include "win/dtwin.h" #endif // _WIN32 +#include "common/dtpthread.h" + int dt_pthread_create(pthread_t *thread, void *(*start_routine)(void *), void *arg) { int ret = 0; @@ -40,7 +42,7 @@ int dt_pthread_create(pthread_t *thread, void *(*start_routine)(void *), void *a ret = pthread_attr_init(&attr); if(ret != 0) { - fprintf(stderr, "[dt_pthread_create] error: pthread_attr_init() returned %i\n", ret); + fprintf(stderr, "[dt_pthread_create] error: pthread_attr_init() returned %s\n", _pthread_ret_mess(ret)); return ret; } @@ -49,27 +51,21 @@ int dt_pthread_create(pthread_t *thread, void *(*start_routine)(void *), void *a ret = pthread_attr_getstacksize(&attr, &stacksize); if(ret != 0) - { - fprintf(stderr, "[dt_pthread_create] error: pthread_attr_getstacksize() returned %i\n", ret); - } + fprintf(stderr, "[dt_pthread_create] error: pthread_attr_getstacksize() returned %s\n", _pthread_ret_mess(ret)); if(ret != 0 || stacksize < WANTED_THREADS_STACK_SIZE) { // looks like we need to bump/set it... ret = pthread_attr_setstacksize(&attr, WANTED_THREADS_STACK_SIZE); if(ret != 0) - { - fprintf(stderr, "[dt_pthread_create] error: pthread_attr_setstacksize() returned %i\n", ret); - } + fprintf(stderr, "[dt_pthread_create] error: pthread_attr_setstacksize() returned %s\n", _pthread_ret_mess(ret)); } if(ret == 0) ret = pthread_create(thread, &attr, start_routine, arg); if(ret != 0) - { - fprintf(stderr, "[dt_pthread_create] error: pthread_create() returned %i\n", ret); - } + fprintf(stderr, "[dt_pthread_create] error: pthread_create() returned %s\n", _pthread_ret_mess(ret)); pthread_attr_destroy(&attr); @@ -95,6 +91,14 @@ void dt_pthread_setname(const char *name) #endif } +int dt_pthread_join(pthread_t thread) +{ + const int ret = pthread_join(thread, NULL); + if(ret != 0) + fprintf(stderr, "[dt_pthread_join] error: %s\n", _pthread_ret_mess(ret)); + return ret; +} + // clang-format off // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py diff --git a/src/common/dtpthread.h b/src/common/dtpthread.h index 0cb87e92db49..f730871bce3c 100644 --- a/src/common/dtpthread.h +++ b/src/common/dtpthread.h @@ -450,7 +450,7 @@ static inline int dt_pthread_mutex_BAD_unlock(dt_pthread_mutex_t *mutex) } int dt_pthread_create(pthread_t *thread, void *(*start_routine)(void *), void *arg); - +int dt_pthread_join(pthread_t thread); void dt_pthread_setname(const char *name); // clang-format off diff --git a/src/control/control.c b/src/control/control.c index f7ddefc0bcd4..b078aad8dcf5 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -344,17 +344,17 @@ void dt_control_shutdown(dt_control_t *control) #ifdef HAVE_GPHOTO2 /* first and always wait for gphoto device updater */ - pthread_join(control->update_gphoto_thread, NULL); + dt_pthread_join(control->update_gphoto_thread); #endif /* wait for kick_on_workers_thread */ - pthread_join(control->kick_on_workers_thread, NULL); + dt_pthread_join(control->kick_on_workers_thread); for(int k = 0; k < control->num_threads-1; k++) - pthread_join(control->thread[k], NULL); + dt_pthread_join(control->thread[k]); for(int k = 0; k < DT_CTL_WORKER_RESERVED; k++) - pthread_join(control->thread_res[k], NULL); + dt_pthread_join(control->thread_res[k]); } void dt_control_cleanup(dt_control_t *control)