# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1614736939 0 # Node ID b9b10bb1f689394fd2d4f65eac03e367c7f067e2 # Parent ef078d219bfc80cfbcf8f78db0c97fb4a9e7f8f6 GTK4: Port dw_mutex_lock() fix from Mac since the GTK4 thread safety is basically the same as the Mac method now. diff -r ef078d219bfc -r b9b10bb1f689 gtk4/dw.c --- a/gtk4/dw.c Tue Mar 02 14:55:01 2021 +0000 +++ b/gtk4/dw.c Wed Mar 03 02:02:19 2021 +0000 @@ -7327,7 +7327,32 @@ */ void API dw_mutex_lock(HMTX mutex) { - pthread_mutex_lock(mutex); + /* We need to handle locks from the main thread differently... + * since we can't stop message processing... otherwise we + * will deadlock... so try to acquire the lock and continue + * processing messages in between tries. + */ + if(_dw_thread == pthread_self()) + { + while(pthread_mutex_trylock(mutex) != 0) + { + /* Process any pending events */ + if(g_main_context_pending(NULL)) + { + do + { + g_main_context_iteration(NULL, FALSE); + } + while(g_main_context_pending(NULL)); + } + else + sched_yield(); + } + } + else + { + pthread_mutex_lock(mutex); + } } /*