summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-10-08 02:58:27 +0600
committersfan5 <sfan5@live.de>2023-10-13 11:36:01 +0200
commitc2d0a4a80fc5c8e1755523b0709e68f973a3d5d3 (patch)
tree0b7c5b497cab25c6d0b2f644e28603b105f64eae
parent1abe908e31c40231e52ab2bc9d13ac66558dea73 (diff)
downloadmpv-c2d0a4a80fc5c8e1755523b0709e68f973a3d5d3.tar.bz2
mpv-c2d0a4a80fc5c8e1755523b0709e68f973a3d5d3.tar.xz
terminal-unix: avoid data race + simplify
tio_orig and tio_orig_set are being touched inside of signal handler which might be invoked from another thread - which makes this a data race. there's no real reason to set tio_orig inside of do_activate_getch2() which is registered as a signal handler. just set it once, in terminal_init(), before any signal handlers come in play. this also allows removing the tio_orig_set variable completely.
-rw-r--r--osdep/terminal-unix.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 0ad3729eda..8e96af3928 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -51,8 +51,7 @@
// buffer all keypresses until ENTER is pressed.
#define INPUT_TIMEOUT 1000
-static volatile struct termios tio_orig;
-static volatile int tio_orig_set;
+static struct termios tio_orig;
static int tty_in = -1, tty_out = -1;
@@ -300,11 +299,6 @@ static void do_activate_getch2(void)
struct termios tio_new;
tcgetattr(tty_in,&tio_new);
- if (!tio_orig_set) {
- tio_orig = tio_new;
- tio_orig_set = 1;
- }
-
tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
tio_new.c_cc[VMIN] = 1;
tio_new.c_cc[VTIME] = 0;
@@ -319,12 +313,7 @@ static void do_deactivate_getch2(void)
return;
enable_kx(false);
-
- if (tio_orig_set) {
- // once set, it will never be set again
- // so we can cast away volatile here
- tcsetattr(tty_in, TCSANOW, (const struct termios *) &tio_orig);
- }
+ tcsetattr(tty_in, TCSANOW, &tio_orig);
getch2_active = 0;
}
@@ -552,6 +541,8 @@ void terminal_init(void)
tty_out = STDOUT_FILENO;
}
+ tcgetattr(tty_in, &tio_orig);
+
// handlers to fix terminal settings
setsigaction(SIGCONT, continue_sighandler, 0, true);
setsigaction(SIGTSTP, stop_sighandler, SA_RESETHAND, false);