Skip to content

Commit

Permalink
Locking global history_mutex
Browse files Browse the repository at this point in the history
While being in darkroom we might want to lock the global history mutex for `dt_styles_apply_to_image()`.

Also _lib_history_button_clicked_callback() should get a global history lock as we select specific
history items that should not be changed from "elsewhere".
  • Loading branch information
jenshannoschwalm committed Jan 31, 2025
1 parent 4ae3442 commit 38375b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/common/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,17 @@ void dt_styles_apply_to_image(const char *name,
const dt_imgid_t imgid)
{
dt_lock_image(imgid);
_styles_apply_to_image_ext(name, duplicate, overwrite, imgid, TRUE);

if(dt_view_get_current() == DT_VIEW_DARKROOM)
{
dt_print(DT_DEBUG_PIPE, "locking global history mutex");
dt_pthread_mutex_lock(&darktable.develop->history_mutex);
_styles_apply_to_image_ext(name, duplicate, overwrite, imgid, TRUE);
dt_pthread_mutex_unlock(&darktable.develop->history_mutex);
}
else
_styles_apply_to_image_ext(name, duplicate, overwrite, imgid, TRUE);

dt_unlock_image(imgid);
}

Expand Down
12 changes: 10 additions & 2 deletions src/libs/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,19 +1240,23 @@ static gboolean _lib_history_button_clicked_callback(GtkWidget *widget,
// shift-click just show the corresponding module in modulegroups
if(dt_modifier_is(e->state, GDK_SHIFT_MASK))
{
dt_pthread_mutex_lock(&darktable.develop->history_mutex);
const int num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "history-number"));
dt_dev_history_item_t *hist = g_list_nth_data(darktable.develop->history, num - 1);
if(hist)
{
dt_dev_modulegroups_switch(darktable.develop, hist->module);
dt_iop_gui_set_expanded(hist->module, TRUE, TRUE);
}
dt_pthread_mutex_unlock(&darktable.develop->history_mutex);
return TRUE;
}

dt_lib_history_t *d = self->data;
reset = TRUE;

dt_pthread_mutex_lock(&darktable.develop->history_mutex);

/* deactivate all toggle buttons */
GList *children = gtk_container_get_children(GTK_CONTAINER(d->history_box));
for(GList *l = children; l != NULL; l = g_list_next(l))
Expand All @@ -1265,8 +1269,11 @@ static gboolean _lib_history_button_clicked_callback(GtkWidget *widget,
g_list_free(children);

reset = FALSE;
if(darktable.gui->reset) return FALSE;

if(darktable.gui->reset)
{
dt_pthread_mutex_unlock(&darktable.develop->history_mutex);
return FALSE;
}
dt_dev_undo_start_record(darktable.develop);

/* revert to given history item. */
Expand All @@ -1288,6 +1295,7 @@ static gboolean _lib_history_button_clicked_callback(GtkWidget *widget,
dt_dev_undo_end_record(darktable.develop);

dt_iop_connect_accels_all();
dt_pthread_mutex_unlock(&darktable.develop->history_mutex);
dt_dev_modulegroups_set(darktable.develop, dt_dev_modulegroups_get(darktable.develop));
return FALSE;
}
Expand Down

0 comments on commit 38375b6

Please sign in to comment.