comparison mac/dw.m @ 693:2f21ee9d7c7b

Experimental change for locking on the main thread... will be committing dw_main_* updates momentarily to go along with this.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 10 Mar 2011 18:30:03 +0000
parents bd909322f40d
children 130ca42c4ae3
comparison
equal deleted inserted replaced
692:bd909322f40d 693:2f21ee9d7c7b
6464 * Parameters: 6464 * Parameters:
6465 * mutex: The handle to the mutex returned by dw_mutex_new(). 6465 * mutex: The handle to the mutex returned by dw_mutex_new().
6466 */ 6466 */
6467 void dw_mutex_lock(HMTX mutex) 6467 void dw_mutex_lock(HMTX mutex)
6468 { 6468 {
6469 DWTID saved = (DWTID)-1; 6469 /* We need to handle locks from the main thread differently...
6470 6470 * since we can't stop message processing... otherwise we
6471 * will deadlock... so try to acquire the lock and continue
6472 * processing messages in between tries.
6473 */
6471 if(DWThread == pthread_self()) 6474 if(DWThread == pthread_self())
6472 { 6475 {
6473 saved = DWThread;
6474 DWThread = (DWTID)-1;
6475 pthread_mutex_unlock(DWRunMutex); 6476 pthread_mutex_unlock(DWRunMutex);
6477 while(pthread_mutex_trylock(mutex) != 0)
6478 {
6479 dw_main_iteration();
6480 }
6481 pthread_mutex_lock(DWRunMutex);
6476 } 6482 }
6477 pthread_mutex_lock(mutex); 6483 else
6478 if(saved != (DWTID)-1)
6479 { 6484 {
6480 DWThread = saved; 6485 pthread_mutex_lock(mutex);
6481 pthread_mutex_lock(DWRunMutex);
6482 } 6486 }
6483 } 6487 }
6484 6488
6485 /* 6489 /*
6486 * Reliquishes the access to the semaphore. 6490 * Reliquishes the access to the semaphore.