Skip to content

Commit

Permalink
Fix missing synchronization in AnsiConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 12, 2023
1 parent a9dc2a3 commit dd7d5e2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ public static int getTerminalWidth() {
}
}

private static boolean initialized;
private static int installed;
private static int virtualProcessing;
private static boolean initialized; // synchronized on AnsiConsole.class
private static int installed; // synchronized on AnsiConsole.class
private static int virtualProcessing; // synchronized on AnsiConsole.class

private AnsiConsole() {}

Expand Down Expand Up @@ -295,12 +295,16 @@ public int getTerminalWidth() {
processor = null;
type = AnsiType.VirtualTerminal;
installer = () -> {
virtualProcessing++;
SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
synchronized (AnsiConsole.class) {
virtualProcessing++;
SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
};
uninstaller = () -> {
if (--virtualProcessing == 0) {
SetConsoleMode(console, mode[0]);
synchronized (AnsiConsole.class) {
if (--virtualProcessing == 0) {
SetConsoleMode(console, mode[0]);
}
}
};
width = kernel32Width;
Expand Down

0 comments on commit dd7d5e2

Please sign in to comment.