Skip to content

Commit

Permalink
Only accept the first dt_control_quit()
Browse files Browse the repository at this point in the history
Strictly prohibit reentrant use of dt_control_quit() and avoid a race condition via
atomic instruction.
  • Loading branch information
jenshannoschwalm committed Dec 14, 2024
1 parent fa427fe commit 09a3d4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void dt_control_init(dt_control_t *s)
s->input_drivers = NULL;
dt_atomic_set_int(&s->running, DT_CONTROL_STATE_DISABLED);
dt_atomic_set_int(&s->pending_jobs, 0);
dt_atomic_set_int(&s->quitting, 0);
s->cups_started = FALSE;

dt_action_define_fallback(DT_ACTION_TYPE_IOP, &dt_action_def_iop);
Expand Down Expand Up @@ -295,9 +296,14 @@ gboolean dt_control_running()

void dt_control_quit()
{
dt_control_t *control = darktable.control;
if(!control) return;

const gboolean quitting = dt_atomic_exch_int(&control->quitting, 1) == 1;
if(quitting) return;

if(dt_control_running())
{
dt_control_t *control = darktable.control;
#ifdef HAVE_PRINT
dt_printers_abort_discovery();
// Cups timeout could be pretty long, at least 30seconds
Expand Down
1 change: 1 addition & 0 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ typedef struct dt_control_t
// job management
dt_atomic_int running;
dt_atomic_int pending_jobs;
dt_atomic_int quitting;
gboolean cups_started;
gboolean export_scheduled;
dt_pthread_mutex_t queue_mutex, cond_mutex;
Expand Down

0 comments on commit 09a3d4f

Please sign in to comment.