Mercurial > dwindows
changeset 700:7953f0471e4d
Some cleanups for the run loop iteration and thread system.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 11 Mar 2011 03:02:58 +0000 |
parents | b79300831495 |
children | c91a1b345f2e |
files | mac/dw.m |
diffstat | 1 files changed, 16 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mac/dw.m Fri Mar 11 02:33:19 2011 +0000 +++ b/mac/dw.m Fri Mar 11 03:02:58 2011 +0000 @@ -23,14 +23,11 @@ dw_mutex_lock(DWThreadMutex); \ _dw_mutex_locked = pthread_self(); \ dw_mutex_lock(DWThreadMutex2); \ - /*NSLog(@"Thread %d asking the main thread to stop %x", (int)pthread_self(), (int)DWObj);*/ \ [DWObj performSelectorOnMainThread:@selector(synchronizeThread:) withObject:nil waitUntilDone:NO]; \ dw_mutex_lock(DWRunMutex); \ - /*NSLog(@"Thread %d proceeding", (int)pthread_self());*/ \ _locked_by_me = TRUE; } } #define DW_MUTEX_UNLOCK { \ if(pthread_self() != DWThread && _locked_by_me == TRUE) { \ - /*NSLog(@"Thread %d releasing", (int)pthread_self());*/ \ dw_mutex_unlock(DWRunMutex); \ dw_mutex_unlock(DWThreadMutex2); \ _dw_mutex_locked = (pthread_t)-1; \ @@ -87,6 +84,7 @@ /* Some internal prototypes */ static void _do_resize(Box *thisbox, int x, int y); int _remove_userdata(UserData **root, char *varname, int all); +void _dw_main_iteration(void); SignalHandler *_get_handler(HWND window, int messageid) { @@ -1737,7 +1735,7 @@ } while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) { - dw_main_iteration(); + _dw_main_iteration(); gettimeofday(&tv, NULL); } if(orig == (DWTID)-1) @@ -1750,10 +1748,8 @@ usleep(milliseconds * 1000); } -/* - * Processes a single message iteration and returns. - */ -void API dw_main_iteration(void) +/* Internal version that doesn't lock the run mutex */ +void _dw_main_iteration(void) { NSDate *distant_future = [NSDate distantFuture]; NSEvent *event = [DWApp nextEventMatchingMask:NSAnyEventMask @@ -1767,6 +1763,16 @@ } /* + * Processes a single message iteration and returns. + */ +void API dw_main_iteration(void) +{ + dw_mutex_lock(DWRunMutex); + _dw_main_iteration(); + dw_mutex_unlock(DWRunMutex); +} + +/* * Cleanly terminates a DW session, should be signal handler safe. * Parameters: * exitcode: Exit code reported to the operating system. @@ -2025,7 +2031,7 @@ while(!dialog->done) { - dw_main_iteration(); + _dw_main_iteration(); } dw_event_close(&dialog->eve); tmp = dialog->result; @@ -6511,7 +6517,7 @@ { while(pthread_mutex_trylock(mutex) != 0) { - dw_main_iteration(); + _dw_main_iteration(); } } else