Jacek Caban : kernelbase: Wait directly on console handles.

Alexandre Julliard julliard at winehq.org
Tue Nov 10 15:30:24 CST 2020


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Nov 10 16:32:01 2020 +0100

kernelbase: Wait directly on console handles.

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

---

 dlls/kernelbase/console.c    | 25 +------------------------
 dlls/kernelbase/kernelbase.h |  1 -
 dlls/kernelbase/sync.c       | 13 +++++--------
 3 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c
index 71c594b3c18..f812b2b9a55 100644
--- a/dlls/kernelbase/console.c
+++ b/dlls/kernelbase/console.c
@@ -37,8 +37,8 @@
 #include "winnls.h"
 #include "winerror.h"
 #include "wincon.h"
+#include "winternl.h"
 #include "wine/condrv.h"
-#include "wine/server.h"
 #include "wine/exception.h"
 #include "wine/debug.h"
 #include "kernelbase.h"
@@ -56,7 +56,6 @@ static CRITICAL_SECTION_DEBUG critsect_debug =
 static CRITICAL_SECTION console_section = { &critsect_debug, -1, 0, 0, 0, 0 };
 
 static HANDLE console_connection;
-static HANDLE console_wait_event;
 static unsigned int console_flags;
 
 #define CONSOLE_INPUT_HANDLE    0x01
@@ -559,32 +558,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW( HANDLE handle, WCHAR
                           written, sizeof(*written), NULL );
 }
 
-HANDLE get_console_wait_handle( HANDLE handle )
-{
-    HANDLE event = 0;
-
-    SERVER_START_REQ( get_console_wait_event )
-    {
-        req->handle = wine_server_obj_handle( console_handle_map( handle ));
-        if (!wine_server_call( req )) event = wine_server_ptr_handle( reply->event );
-    }
-    SERVER_END_REQ;
-    if (event)
-    {
-        if (InterlockedCompareExchangePointer( &console_wait_event, event, 0 )) NtClose( event );
-        handle = console_wait_event;
-    }
-    return handle;
-}
-
 
 /***********************************************************************
  *	FreeConsole   (kernelbase.@)
  */
 BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
 {
-    HANDLE event;
-
     RtlEnterCriticalSection( &console_section );
 
     NtClose( console_connection );
@@ -598,8 +577,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
     if (console_flags & CONSOLE_ERROR_HANDLE)  NtClose( GetStdHandle( STD_ERROR_HANDLE ));
     console_flags = 0;
 
-    if ((event = InterlockedExchangePointer( &console_wait_event, NULL ))) NtClose( event );
-
     RtlLeaveCriticalSection( &console_section );
     return TRUE;
 }
diff --git a/dlls/kernelbase/kernelbase.h b/dlls/kernelbase/kernelbase.h
index 551542e5725..836d636b47b 100644
--- a/dlls/kernelbase/kernelbase.h
+++ b/dlls/kernelbase/kernelbase.h
@@ -36,7 +36,6 @@ extern DWORD file_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen )
 extern void init_startup_info( RTL_USER_PROCESS_PARAMETERS *params ) DECLSPEC_HIDDEN;
 extern void init_locale(void) DECLSPEC_HIDDEN;
 extern void init_console(void) DECLSPEC_HIDDEN;
-extern HANDLE get_console_wait_handle( HANDLE handle ) DECLSPEC_HIDDEN;
 
 extern const WCHAR windows_dir[] DECLSPEC_HIDDEN;
 extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
diff --git a/dlls/kernelbase/sync.c b/dlls/kernelbase/sync.c
index 13a9938e7c6..e8e51b1c573 100644
--- a/dlls/kernelbase/sync.c
+++ b/dlls/kernelbase/sync.c
@@ -211,17 +211,14 @@ ULONGLONG WINAPI DECLSPEC_HOTPATCH GetTickCount64(void)
  ***********************************************************************/
 
 
-static HANDLE normalize_handle_if_console( HANDLE handle )
+static HANDLE normalize_std_handle( HANDLE handle )
 {
     if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
         (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
         (handle == (HANDLE)STD_ERROR_HANDLE))
-        handle = GetStdHandle( HandleToULong(handle) );
+        return GetStdHandle( HandleToULong(handle) );
 
-    /* even screen buffer console handles are waitable, and are
-     * handled as a handle to the console itself
-     */
-    return is_console_handle( handle ) ? get_console_wait_handle( handle ) : handle;
+    return handle;
 }
 
 
@@ -235,7 +232,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH RegisterWaitForSingleObjectEx( HANDLE handle, WA
 
     TRACE( "%p %p %p %d %d\n", handle, callback, context, timeout, flags );
 
-    handle = normalize_handle_if_console( handle );
+    handle = normalize_std_handle( handle );
     if (!set_ntstatus( RtlRegisterWait( &ret, handle, callback, context, timeout, flags ))) return NULL;
     return ret;
 }
@@ -340,7 +337,7 @@ DWORD WINAPI DECLSPEC_HOTPATCH WaitForMultipleObjectsEx( DWORD count, const HAND
         SetLastError(ERROR_INVALID_PARAMETER);
         return WAIT_FAILED;
     }
-    for (i = 0; i < count; i++) hloc[i] = normalize_handle_if_console( handles[i] );
+    for (i = 0; i < count; i++) hloc[i] = normalize_std_handle( handles[i] );
 
     status = NtWaitForMultipleObjects( count, hloc, !wait_all, alertable,
                                        get_nt_timeout( &time, timeout ) );




More information about the wine-cvs mailing list