# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1300141501 0 # Node ID 55f22b39ab571d853543ccb796f81e121e9125a5 # Parent f190b5c2ce162861e3400da1b4469fde138eb3d0 Changes to correctly set the main thread and lock the run mutex when not running a loop and when called from a callback. diff -r f190b5c2ce16 -r 55f22b39ab57 mac/dw.m --- a/mac/dw.m Mon Mar 14 21:43:28 2011 +0000 +++ b/mac/dw.m Mon Mar 14 22:25:01 2011 +0000 @@ -1937,9 +1937,9 @@ DWTID orig = DWThread; NSDate *until = [NSDate dateWithTimeIntervalSinceNow:(milliseconds/1000.0)]; - dw_mutex_lock(DWRunMutex); if(orig == (DWTID)-1) { + dw_mutex_lock(DWRunMutex); DWThread = curr; } /* Process any pending events */ @@ -1950,8 +1950,8 @@ if(orig == (DWTID)-1) { DWThread = orig; + dw_mutex_unlock(DWRunMutex); } - dw_mutex_unlock(DWRunMutex); } else { @@ -1980,9 +1980,20 @@ */ void API dw_main_iteration(void) { - dw_mutex_lock(DWRunMutex); - _dw_main_iteration([NSDate distantPast]); - dw_mutex_unlock(DWRunMutex); + DWTID curr = pthread_self(); + + if(DWThread == (DWTID)-1) + { + dw_mutex_lock(DWRunMutex); + DWThread = curr; + _dw_main_iteration([NSDate distantPast]); + DWThread = (DWTID)-1; + dw_mutex_unlock(DWRunMutex); + } + else if(DWThread == curr) + { + _dw_main_iteration([NSDate distantPast]); + } } /*