From fd83308b0b89dc560df77221dcd509bca336a323 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 18 Apr 2022 14:40:59 +0200 Subject: [PATCH] winex11: Use pthread for win data locking. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/winex11.drv/window.c | 28 +++++++++++++++------------- dlls/winex11.drv/x11drv.h | 3 +-- dlls/winex11.drv/x11drv_main.c | 4 +--- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c index dd5c298c7a6..3f20fc9c7d2 100644 --- a/dlls/winex11.drv/window.c +++ b/dlls/winex11.drv/window.c @@ -86,7 +86,7 @@ BOOL clipping_cursor = FALSE; XContext winContext = 0; /* X context to associate a struct x11drv_win_data to an hwnd */ -XContext win_data_context = 0; +static XContext win_data_context = 0; /* time of last user event and window where it's stored */ static Time last_user_time; @@ -99,14 +99,7 @@ static const WCHAR whole_window_prop[] = static const WCHAR clip_window_prop[] = {'_','_','w','i','n','e','_','x','1','1','_','c','l','i','p','_','w','i','n','d','o','w',0}; -static CRITICAL_SECTION win_data_section; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &win_data_section, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": win_data_section") } -}; -static CRITICAL_SECTION win_data_section = { &critsect_debug, -1, 0, 0, 0, 0 }; +static pthread_mutex_t win_data_mutex = PTHREAD_MUTEX_INITIALIZER; /*********************************************************************** @@ -215,7 +208,7 @@ static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd ) data->display = display; data->vis = default_visual; data->hwnd = hwnd; - EnterCriticalSection( &win_data_section ); + pthread_mutex_lock( &win_data_mutex ); XSaveContext( gdi_display, (XID)hwnd, win_data_context, (char *)data ); } return data; @@ -1938,10 +1931,10 @@ struct x11drv_win_data *get_win_data( HWND hwnd ) char *data; if (!hwnd) return NULL; - EnterCriticalSection( &win_data_section ); + pthread_mutex_lock( &win_data_mutex ); if (!XFindContext( gdi_display, (XID)hwnd, win_data_context, &data )) return (struct x11drv_win_data *)data; - LeaveCriticalSection( &win_data_section ); + pthread_mutex_unlock( &win_data_mutex ); return NULL; } @@ -1953,7 +1946,7 @@ struct x11drv_win_data *get_win_data( HWND hwnd ) */ void release_win_data( struct x11drv_win_data *data ) { - if (data) LeaveCriticalSection( &win_data_section ); + if (data) pthread_mutex_unlock( &win_data_mutex ); } @@ -3039,3 +3032,12 @@ void X11DRV_FlashWindowEx( FLASHWINFO *pfinfo ) } release_win_data( data ); } + +void init_win_context(void) +{ + init_recursive_mutex( &win_data_mutex ); + + winContext = XUniqueContext(); + win_data_context = XUniqueContext(); + cursor_context = XUniqueContext(); +} diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index ed7a75a8d17..95e4b4ff29a 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -661,6 +661,7 @@ extern void change_systray_owner( Display *display, Window systray_window ) DECL extern void update_systray_balloon_position(void) DECLSPEC_HIDDEN; extern HWND create_foreign_window( Display *display, Window window ) DECLSPEC_HIDDEN; extern BOOL update_clipboard( HWND hwnd ) DECLSPEC_HIDDEN; +extern void init_win_context(void) DECLSPEC_HIDDEN; static inline void mirror_rect( const RECT *window_rect, RECT *rect ) { @@ -672,8 +673,6 @@ static inline void mirror_rect( const RECT *window_rect, RECT *rect ) /* X context to associate a hwnd to an X window */ extern XContext winContext DECLSPEC_HIDDEN; -/* X context to associate a struct x11drv_win_data to an hwnd */ -extern XContext win_data_context DECLSPEC_HIDDEN; /* X context to associate an X cursor to a Win32 cursor handle */ extern XContext cursor_context DECLSPEC_HIDDEN; diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c index 539f49197a3..49aff9571bc 100644 --- a/dlls/winex11.drv/x11drv_main.c +++ b/dlls/winex11.drv/x11drv_main.c @@ -683,9 +683,7 @@ static BOOL process_attach(void) XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms ); - winContext = XUniqueContext(); - win_data_context = XUniqueContext(); - cursor_context = XUniqueContext(); + init_win_context(); if (TRACE_ON(synchronous)) XSynchronize( display, True );