Mercurial > dwindows
changeset 2338:b9b10bb1f689
GTK4: Port dw_mutex_lock() fix from Mac since the GTK4 thread safety is
basically the same as the Mac method now.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 03 Mar 2021 02:02:19 +0000 |
parents | ef078d219bfc |
children | 6ad84c425bbd |
files | gtk4/dw.c |
diffstat | 1 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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); + } } /*