Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dt_atomic for control->running #17978

Merged
Merged
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
2 changes: 1 addition & 1 deletion src/common/darktable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
if(dbfilename_from_command && !strcmp(dbfilename_from_command, ":memory:"))
dt_gui_presets_init(); // init preset db schema.

g_atomic_int_set(&darktable.control->running, DT_CONTROL_STATE_DISABLED);
dt_atomic_set_int(&darktable.control->running, DT_CONTROL_STATE_DISABLED);
dt_pthread_mutex_init(&darktable.control->log_mutex, NULL);
}

Expand Down
29 changes: 15 additions & 14 deletions src/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void dt_control_init(dt_control_t *s)
s->confirm_mapping = TRUE;
s->widget_definitions = g_ptr_array_new ();
s->input_drivers = NULL;
s->running = DT_CONTROL_STATE_DISABLED;
dt_atomic_set_int(&s->running, DT_CONTROL_STATE_DISABLED);
s->cups_started = FALSE;

dt_action_define_fallback(DT_ACTION_TYPE_IOP, &dt_action_def_iop);
Expand Down Expand Up @@ -289,7 +289,7 @@ void dt_control_change_cursor(dt_cursor_t curs)
gboolean dt_control_running()
{
dt_control_t *dc = darktable.control;
const gint status = dc ? g_atomic_int_get(&dc->running) : DT_CONTROL_STATE_DISABLED;
const int status = dc ? dt_atomic_get_int(&dc->running) : DT_CONTROL_STATE_DISABLED;
return status == DT_CONTROL_STATE_RUNNING;
}

Expand All @@ -309,7 +309,7 @@ void dt_control_quit()

dt_pthread_mutex_lock(&dc->cond_mutex);
// set the "pending cleanup work" flag to be handled in dt_control_shutdown()
g_atomic_int_set(&dc->running, DT_CONTROL_STATE_CLEANUP);
dt_atomic_set_int(&dc->running, DT_CONTROL_STATE_CLEANUP);
dt_pthread_mutex_unlock(&dc->cond_mutex);
}

Expand All @@ -326,7 +326,7 @@ void dt_control_shutdown(dt_control_t *s)
return;

dt_pthread_mutex_lock(&s->cond_mutex);
const gboolean cleanup = g_atomic_int_exchange(&s->running, DT_CONTROL_STATE_DISABLED) == DT_CONTROL_STATE_CLEANUP;
const gboolean cleanup = dt_atomic_exch_int(&s->running, DT_CONTROL_STATE_DISABLED) == DT_CONTROL_STATE_CLEANUP;
pthread_cond_broadcast(&s->cond);
dt_pthread_mutex_unlock(&s->cond_mutex);

Expand All @@ -342,19 +342,20 @@ void dt_control_shutdown(dt_control_t *s)
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] closing control threads");

/* then wait for kick_on_workers_thread */
if(!err) err |= pthread_join(s->kick_on_workers_thread, NULL);
err = pthread_join(s->kick_on_workers_thread, NULL);
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] joined kicker%s", err ? ", error" : "");

for(int k = 0; k < s->num_threads; k++)
// pthread_kill(s->thread[k], 9);
if(!err) err |= pthread_join(s->thread[k], NULL);
for(int k = 0; k < s->num_threads-1; k++)
{
err = pthread_join(s->thread[k], NULL);
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] joined num_thread %i%s", k, err ? ", error" : "");
}

for(int k = 0; k < DT_CTL_WORKER_RESERVED; k++)
// pthread_kill(s->thread_res[k], 9);
if(!err) err |= pthread_join(s->thread_res[k], NULL);

if(err != 0)
dt_print(DT_DEBUG_ALWAYS, "[dt_control_shutdown] couldn't join all threads, problems ahead");

{
err = pthread_join(s->thread_res[k], NULL);
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] joined worker %i%s", k, err ? ", error" : "");
}
}

void dt_control_cleanup(dt_control_t *s)
Expand Down
2 changes: 1 addition & 1 deletion src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ typedef struct dt_control_t
double last_expose_time;

// job management
gint running;
dt_atomic_int running;
gboolean cups_started;
gboolean export_scheduled;
dt_pthread_mutex_t queue_mutex, cond_mutex;
Expand Down
Loading