[PATCH 01/11] wineandroid: Use pthread for locking in opengl.c.

Jacek Caban wine at gitlab.winehq.org
Mon Jun 6 19:33:00 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
 dlls/wineandroid.drv/Makefile.in |  5 +++--
 dlls/wineandroid.drv/android.h   |  2 ++
 dlls/wineandroid.drv/init.c      |  6 ++++++
 dlls/wineandroid.drv/opengl.c    | 25 +++++++++----------------
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/dlls/wineandroid.drv/Makefile.in b/dlls/wineandroid.drv/Makefile.in
index 3f9a16bea4f..5426fc75b94 100644
--- a/dlls/wineandroid.drv/Makefile.in
+++ b/dlls/wineandroid.drv/Makefile.in
@@ -1,6 +1,7 @@
 EXTRADEFS = -DWINE_NO_LONG_TYPES
-MODULE  = wineandroid.drv
-IMPORTS = user32 ntoskrnl win32u
+MODULE    = wineandroid.drv
+IMPORTS   = user32 ntoskrnl win32u
+EXTRALIBS = $(PTHREAD_LIBS)
 
 EXTRADLLFLAGS = -mcygwin
 
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h
index 91f6dc83791..4348818aaf2 100644
--- a/dlls/wineandroid.drv/android.h
+++ b/dlls/wineandroid.drv/android.h
@@ -24,6 +24,7 @@
 #include <limits.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <pthread.h>
 #include <jni.h>
 #include <android/log.h>
 #include <android/input.h>
@@ -51,6 +52,7 @@ DECL_FUNCPTR( ANativeWindow_release );
  * OpenGL driver
  */
 
+extern pthread_mutex_t drawable_mutex DECLSPEC_HIDDEN;
 extern void update_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN;
 extern void destroy_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN;
 extern struct opengl_funcs *get_wgl_driver( UINT version ) DECLSPEC_HIDDEN;
diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c
index f06eb6471c5..33acb4376c5 100644
--- a/dlls/wineandroid.drv/init.c
+++ b/dlls/wineandroid.drv/init.c
@@ -558,6 +558,7 @@ unsigned short *p_java_gdt_sel = NULL;
 
 static BOOL process_attach(void)
 {
+    pthread_mutexattr_t attr;
     jclass class;
     jobject object;
     JNIEnv *jni_env;
@@ -574,6 +575,11 @@ static BOOL process_attach(void)
 
     load_hardware_libs();
 
+    pthread_mutexattr_init( &attr );
+    pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
+    pthread_mutex_init( &drawable_mutex, &attr );
+    pthread_mutexattr_destroy( &attr );
+
     if ((java_vm = *p_java_vm))  /* running under Java */
     {
 #ifdef __i386__
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c
index afd1ef3f7a5..0c4f14e7cff 100644
--- a/dlls/wineandroid.drv/opengl.c
+++ b/dlls/wineandroid.drv/opengl.c
@@ -105,14 +105,7 @@ static struct list gl_drawables = LIST_INIT( gl_drawables );
 static void (*pglFinish)(void);
 static void (*pglFlush)(void);
 
-static CRITICAL_SECTION drawable_section;
-static CRITICAL_SECTION_DEBUG critsect_debug =
-{
-    0, 0, &drawable_section,
-    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
-      0, 0, { (DWORD_PTR)(__FILE__ ": drawable_section") }
-};
-static CRITICAL_SECTION drawable_section = { &critsect_debug, -1, 0, 0, 0, 0 };
+pthread_mutex_t drawable_mutex;
 
 static inline BOOL is_onscreen_pixel_format( int format )
 {
@@ -130,7 +123,7 @@ static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format )
     gl->window = create_ioctl_window( hwnd, TRUE, 1.0f );
     gl->surface = 0;
     gl->pbuffer = p_eglCreatePbufferSurface( display, pixel_formats[gl->format - 1].config, attribs );
-    EnterCriticalSection( &drawable_section );
+    pthread_mutex_lock( &drawable_mutex );
     list_add_head( &gl_drawables, &gl->entry );
     return gl;
 }
@@ -139,26 +132,26 @@ static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
 {
     struct gl_drawable *gl;
 
-    EnterCriticalSection( &drawable_section );
+    pthread_mutex_lock( &drawable_mutex );
     LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry )
     {
         if (hwnd && gl->hwnd == hwnd) return gl;
         if (hdc && gl->hdc == hdc) return gl;
     }
-    LeaveCriticalSection( &drawable_section );
+    pthread_mutex_unlock( &drawable_mutex );
     return NULL;
 }
 
 static void release_gl_drawable( struct gl_drawable *gl )
 {
-    if (gl) LeaveCriticalSection( &drawable_section );
+    if (gl) pthread_mutex_unlock( &drawable_mutex );
 }
 
 void destroy_gl_drawable( HWND hwnd )
 {
     struct gl_drawable *gl;
 
-    EnterCriticalSection( &drawable_section );
+    pthread_mutex_lock( &drawable_mutex );
     LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry )
     {
         if (gl->hwnd != hwnd) continue;
@@ -169,7 +162,7 @@ void destroy_gl_drawable( HWND hwnd )
         HeapFree( GetProcessHeap(), 0, gl );
         break;
     }
-    LeaveCriticalSection( &drawable_section );
+    pthread_mutex_unlock( &drawable_mutex );
 }
 
 static BOOL refresh_context( struct wgl_context *ctx )
@@ -439,9 +432,9 @@ static struct wgl_context * WINAPI android_wglCreateContext( HDC hdc )
  */
 static BOOL WINAPI android_wglDeleteContext( struct wgl_context *ctx )
 {
-    EnterCriticalSection( &drawable_section );
+    pthread_mutex_lock( &drawable_mutex );
     list_remove( &ctx->entry );
-    LeaveCriticalSection( &drawable_section );
+    pthread_mutex_unlock( &drawable_mutex );
     p_eglDestroyContext( display, ctx->context );
     return HeapFree( GetProcessHeap(), 0, ctx );
 }
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/193



More information about the wine-devel mailing list