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.
This commit is contained in:
Ben Noordhuis 2022-10-01 13:43:47 +02:00 committed by GitHub
parent cdbba74d7a
commit 71a782b641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;