From 9f514fe239376ffb2d9aebab618746220ec12961 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 9 Nov 2003 00:34:43 +0000 Subject: [PATCH] Avoid the XSync call in X11DRV_expect_error by storing the current request number and checking that on errors. Moved the XSync call from X11DRV_check_error into the callers so that it can be avoided for requests that already wait for a reply. --- dlls/x11drv/event.c | 1 + dlls/x11drv/x11drv_main.c | 8 +++++--- graphics/x11drv/dib.c | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c index e3480e4745a..3f640f77d8f 100644 --- a/dlls/x11drv/event.c +++ b/dlls/x11drv/event.c @@ -419,6 +419,7 @@ static void set_focus( HWND hwnd, Time time ) TRACE( "setting focus to %p (%lx) time=%ld\n", focus, win, time ); X11DRV_expect_error( display, set_focus_error_handler, NULL ); XSetInputFocus( display, win, RevertToParent, time ); + XSync( display, False ); if (X11DRV_check_error()) TRACE("got BadMatch, ignoring\n" ); } } diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c index 8fba17dbed4..e91534100e0 100644 --- a/dlls/x11drv/x11drv_main.c +++ b/dlls/x11drv/x11drv_main.c @@ -91,6 +91,7 @@ static x11drv_error_callback err_callback; /* current callback for error */ static Display *err_callback_display; /* display callback is set for */ static void *err_callback_arg; /* error callback argument */ static int err_callback_result; /* error callback result */ +static unsigned long err_serial; /* serial number of first request */ static int (*old_error_handler)( Display *, XErrorEvent * ); #define IS_OPTION_TRUE(ch) \ @@ -109,11 +110,11 @@ static int (*old_error_handler)( Display *, XErrorEvent * ); void X11DRV_expect_error( Display *display, x11drv_error_callback callback, void *arg ) { wine_tsx11_lock(); - XSync( display, False ); err_callback = callback; err_callback_display = display; err_callback_arg = arg; err_callback_result = 0; + err_serial = NextRequest(display); } @@ -122,11 +123,11 @@ void X11DRV_expect_error( Display *display, x11drv_error_callback callback, void * * Check if an expected X11 error occurred; return non-zero if yes. * Also release the x11 lock obtained in X11DRV_expect_error. + * The caller is responsible for calling XSync first if necessary. */ int X11DRV_check_error(void) { int ret; - XSync( err_callback_display, False ); err_callback = NULL; ret = err_callback_result; wine_tsx11_unlock(); @@ -139,7 +140,8 @@ int X11DRV_check_error(void) */ static int error_handler( Display *display, XErrorEvent *error_evt ) { - if (err_callback && display == err_callback_display) + if (err_callback && display == err_callback_display && + (long)(error_evt->serial - err_serial) >= 0) { if ((err_callback_result = err_callback( display, error_evt, err_callback_arg ))) { diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c index 281251e4b37..6bb1082c103 100644 --- a/graphics/x11drv/dib.c +++ b/graphics/x11drv/dib.c @@ -5674,6 +5674,7 @@ static XImage *X11DRV_XShmCreateImage( int width, int height, int bpp, shminfo->readOnly = FALSE; X11DRV_expect_error( gdi_display, XShmErrorHandler, NULL ); ok = (XShmAttach( gdi_display, shminfo ) != 0); + XSync( gdi_display, False ); if (X11DRV_check_error()) ok = FALSE; if (ok) {