Jacek Caban : conhost: Delay creating input thread in Unix mode.

Alexandre Julliard julliard at winehq.org
Mon Sep 21 15:12:16 CDT 2020


Module: wine
Branch: master
Commit: 158471d676e799d3d23a356b442ecc4afd2ade57
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=158471d676e799d3d23a356b442ecc4afd2ade57

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Sep 21 17:06:11 2020 +0200

conhost: Delay creating input thread in Unix mode.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/conhost/conhost.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c
index 3f7b5fb914..0de55af14c 100644
--- a/programs/conhost/conhost.c
+++ b/programs/conhost/conhost.c
@@ -99,6 +99,7 @@ struct console
     unsigned int          input_cp;            /* console input codepage */
     unsigned int          output_cp;           /* console output codepage */
     unsigned int          win;                 /* window handle if backend supports it */
+    HANDLE                input_thread;        /* input thread handle */
     HANDLE                tty_input;           /* handle to tty input stream */
     HANDLE                tty_output;          /* handle to tty output stream */
     char                  tty_buffer[4096];    /* tty output buffer */
@@ -1681,11 +1682,20 @@ static DWORD WINAPI tty_input( void *param )
 
     EnterCriticalSection( &console_section );
     if (console->read_ioctl) read_complete( console, status, NULL, 0, FALSE );
+    CloseHandle( console->input_thread );
+    console->input_thread = NULL;
     LeaveCriticalSection( &console_section );
 
     return 0;
 }
 
+static BOOL ensure_tty_input_thread( struct console *console )
+{
+    if (!console->input_thread)
+        console->input_thread = CreateThread( NULL, 0, tty_input, console, 0, NULL );
+    return console->input_thread != NULL;
+}
+
 static NTSTATUS screen_buffer_activate( struct screen_buffer *screen_buffer )
 {
     RECT update_rect;
@@ -2424,6 +2434,7 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code,
 
     case IOCTL_CONDRV_READ_CONSOLE:
         if (in_size || *out_size % sizeof(WCHAR)) return STATUS_INVALID_PARAMETER;
+        ensure_tty_input_thread( console );
         return read_console( console, *out_size );
 
     case IOCTL_CONDRV_READ_INPUT:
@@ -2431,6 +2442,7 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code,
             unsigned int blocking;
             NTSTATUS status;
             if (in_size && in_size != sizeof(blocking)) return STATUS_INVALID_PARAMETER;
+            ensure_tty_input_thread( console );
             blocking = in_size && *(unsigned int *)in_data;
             if (blocking && !console->record_count && *out_size)
             {
@@ -2683,7 +2695,7 @@ static int main_loop( struct console *console, HANDLE signal )
 int __cdecl wmain(int argc, WCHAR *argv[])
 {
     int headless = 0, i, width = 0, height = 0;
-    HANDLE signal = NULL, input_thread;
+    HANDLE signal = NULL;
     WCHAR *end;
 
     static struct console console;
@@ -2764,10 +2776,7 @@ int __cdecl wmain(int argc, WCHAR *argv[])
         console.tty_input  = GetStdHandle( STD_INPUT_HANDLE );
         console.tty_output = GetStdHandle( STD_OUTPUT_HANDLE );
         init_tty_output( &console );
-
-        if (!(input_thread = CreateThread( NULL, 0, tty_input, &console, 0, NULL )))
-            return 1;
-        CloseHandle( input_thread );
+        if (!console.is_unix && !ensure_tty_input_thread( &console )) return 1;
     }
 
     return main_loop( &console, signal );




More information about the wine-cvs mailing list