From 71a782b64125b2dc1d9ecdf62aec934df55c53be Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 1 Oct 2022 13:43:47 +0200 Subject: [PATCH] unix: simplify atomic op in uv_tty_reset_mode() (#3773) Compare-and-exchange is only useful in a loop. Replace it with a simple exchange. --- src/unix/tty.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/unix/tty.c b/src/unix/tty.c index a5bad72f..4c220e56 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -447,13 +447,11 @@ uv_handle_type uv_guess_handle(uv_file file) { */ int uv_tty_reset_mode(void) { int saved_errno; - int expected; int err; saved_errno = errno; - expected = 0; - if (!atomic_compare_exchange_strong(&termios_spinlock, &expected, 1)) + if (atomic_exchange(&termios_spinlock, 1)) return UV_EBUSY; /* In uv_tty_set_mode(). */ err = 0;