Mercurial > dwindows
comparison gtk4/dw.c @ 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 |
comparison
equal
deleted
inserted
replaced
2337:ef078d219bfc | 2338:b9b10bb1f689 |
---|---|
7325 * Parameters: | 7325 * Parameters: |
7326 * mutex: The handle to the mutex returned by dw_mutex_new(). | 7326 * mutex: The handle to the mutex returned by dw_mutex_new(). |
7327 */ | 7327 */ |
7328 void API dw_mutex_lock(HMTX mutex) | 7328 void API dw_mutex_lock(HMTX mutex) |
7329 { | 7329 { |
7330 pthread_mutex_lock(mutex); | 7330 /* We need to handle locks from the main thread differently... |
7331 * since we can't stop message processing... otherwise we | |
7332 * will deadlock... so try to acquire the lock and continue | |
7333 * processing messages in between tries. | |
7334 */ | |
7335 if(_dw_thread == pthread_self()) | |
7336 { | |
7337 while(pthread_mutex_trylock(mutex) != 0) | |
7338 { | |
7339 /* Process any pending events */ | |
7340 if(g_main_context_pending(NULL)) | |
7341 { | |
7342 do | |
7343 { | |
7344 g_main_context_iteration(NULL, FALSE); | |
7345 } | |
7346 while(g_main_context_pending(NULL)); | |
7347 } | |
7348 else | |
7349 sched_yield(); | |
7350 } | |
7351 } | |
7352 else | |
7353 { | |
7354 pthread_mutex_lock(mutex); | |
7355 } | |
7331 } | 7356 } |
7332 | 7357 |
7333 /* | 7358 /* |
7334 * Tries to gain access to the semaphore. | 7359 * Tries to gain access to the semaphore. |
7335 * Parameters: | 7360 * Parameters: |