From 5f4e7b0368940682706916fec6d22befd4e82703 Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Wed, 2 Mar 2022 16:00:31 +0900 Subject: Cygwin: console, pty: Revamp the acquire/release_attach_mutex timing. - This patch revises the acquiring/releasing timing for attach_mutex to make the period in which it is being acquired shorter. Further, acquiring/releasing are added to where they are missing but needed. --- winsup/cygwin/select.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'winsup/cygwin/select.cc') diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 80a9527..64e35cf 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -1095,8 +1095,6 @@ fhandler_fifo::select_except (select_stuff *ss) return s; } -extern DWORD mutex_timeout; /* defined in fhandler_termios.cc */ - static int peek_console (select_record *me, bool) { @@ -1123,7 +1121,6 @@ peek_console (select_record *me, bool) set_handle_or_return_if_not_open (h, me); fh->acquire_input_mutex (mutex_timeout); - acquire_attach_mutex (mutex_timeout); while (!fh->input_ready && !fh->get_cons_readahead_valid ()) { if (fh->bg_check (SIGTTIN, true) <= bg_eof) @@ -1132,8 +1129,14 @@ peek_console (select_record *me, bool) fh->release_input_mutex (); return me->read_ready = true; } - else if (!PeekConsoleInputW (h, &irec, 1, &events_read) || !events_read) - break; + else + { + acquire_attach_mutex (mutex_timeout); + BOOL r = PeekConsoleInputW (h, &irec, 1, &events_read); + release_attach_mutex (); + if (!r || !events_read) + break; + } if (fhandler_console::input_winch == fh->process_input_message () && global_sigs[SIGWINCH].sa_handler != SIG_IGN && global_sigs[SIGWINCH].sa_handler != SIG_DFL) @@ -1144,7 +1147,6 @@ peek_console (select_record *me, bool) return -1; } } - release_attach_mutex (); fh->release_input_mutex (); if (fh->input_ready || fh->get_cons_readahead_valid ()) return me->read_ready = true; -- cgit v1.1