Hand out hotkey bindings as a snapshot
Hotkeys.all() returned its synchronised list, and every reader had to lock it while iterating: a lock owned by one class and taken by four others. It now returns a copy, and the lock stays inside Hotkeys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,10 +70,8 @@ final class HotkeyService {
|
||||
|
||||
/** The binding for an action with no argument, or {@code null} when unbound. */
|
||||
Hotkey find(HotkeyAction action) {
|
||||
synchronized (hotkeys.all()) {
|
||||
for (Hotkey h : hotkeys.all()) {
|
||||
if (h.action == action) return h;
|
||||
}
|
||||
for (Hotkey h : hotkeys.all()) {
|
||||
if (h.action == action) return h;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,7 @@ final class HotkeysPanel extends JPanel {
|
||||
this.service = service;
|
||||
setBorder(new ScaledEmptyBorder(8, 8, 8, 8));
|
||||
|
||||
synchronized (service.all()) {
|
||||
for (Hotkey h : service.all()) working.add(h.copy());
|
||||
}
|
||||
for (Hotkey h : service.all()) working.add(h.copy());
|
||||
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setRowHeight(table.getRowHeight() + UIScale.scale(4));
|
||||
@@ -113,9 +111,7 @@ final class HotkeysPanel extends JPanel {
|
||||
/** Picks the stored bindings up again after something else changed them. */
|
||||
void reload() {
|
||||
working.clear();
|
||||
synchronized (service.all()) {
|
||||
for (Hotkey h : service.all()) working.add(h.copy());
|
||||
}
|
||||
for (Hotkey h : service.all()) working.add(h.copy());
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -325,10 +325,8 @@ final class VoiceActivationPanel extends FormPanel {
|
||||
dlg.setVisible(true);
|
||||
if (!dlg.isConfirmed()) return;
|
||||
List<Hotkey> updated = new java.util.ArrayList<>();
|
||||
synchronized (hotkeys.all()) {
|
||||
for (Hotkey h : hotkeys.all()) {
|
||||
if (h != existing) updated.add(h.copy());
|
||||
}
|
||||
for (Hotkey h : hotkeys.all()) {
|
||||
if (h != existing) updated.add(h.copy());
|
||||
}
|
||||
updated.add(dlg.result());
|
||||
hotkeys.replaceAll(updated);
|
||||
|
||||
Reference in New Issue
Block a user