Revision: 4209 http://skim-app.svn.sourceforge.net/skim-app/?rev=4209&view=rev Author: hofman Date: 2008-07-14 11:21:51 -0700 (Mon, 14 Jul 2008)
Log Message: ----------- Set stop flag in async DO server before messaging the server thread, so it is guaranteed to finish the runloop. Cleanup server thread after the runloop has finished, so it is guaranteed to be executed. Modified Paths: -------------- trunk/SKPDFSynchronizer.m Modified: trunk/SKPDFSynchronizer.m =================================================================== --- trunk/SKPDFSynchronizer.m 2008-07-14 17:14:00 UTC (rev 4208) +++ trunk/SKPDFSynchronizer.m 2008-07-14 18:21:51 UTC (rev 4209) @@ -79,7 +79,7 @@ }; @protocol SKPDFSynchronizerServerThread -- (oneway void)cleanup; +- (oneway void)stopRunning; - (oneway void)serverFindFileAndLineForLocation:(NSPoint)point inRect:(NSRect)rect atPageIndex:(unsigned int)pageIndex; - (oneway void)serverFindPageAndLocationForLine:(int)line inFile:(bycopy NSString *)file; @end @@ -225,10 +225,10 @@ #pragma mark | DO server - (void)stopDOServer { - // this cleans up the connections, ports and proxies on both sides - [serverOnServerThread cleanup]; - // we're in the main thread, so set the stop flag + // set the stop flag so any running task may finish OSAtomicCompareAndSwap32Barrier(1, 0, (int32_t *)&serverFlags->shouldKeepRunning); + // this is really only necessary to tickle the server thread's runloop so it will finish + [serverOnServerThread stopRunning]; // clean up the connection in the main thread; don't invalidate the ports, since they're still in use [mainThreadConnection setRootObject:nil]; @@ -253,7 +253,7 @@ #pragma mark Main thread #pragma mark | DO server -- (oneway void)setLocalServer:(byref id)anObject { +- (void)setLocalServer:(byref id)anObject { [anObject setProtocolForProxy:@protocol(SKPDFSynchronizerServerThread)]; serverOnServerThread = [anObject retain]; } @@ -273,26 +273,9 @@ #pragma mark Server thread #pragma mark | DO server -- (oneway void)cleanup { - // clean up the connection in the server thread - [localThreadConnection setRootObject:nil]; - - // this frees up the CFMachPorts created in -init - [[localThreadConnection receivePort] invalidate]; - [[localThreadConnection sendPort] invalidate]; - [localThreadConnection invalidate]; - [localThreadConnection release]; - localThreadConnection = nil; - - [serverOnMainThread release]; - serverOnMainThread = nil; - -#ifdef SYNCTEX_FEATURE - if (scanner) { - synctex_scanner_free(scanner); - scanner = NULL; - } -#endif +- (oneway void)stopRunning {log_method(); + // not really necessary, as the main thread should already have done this + OSAtomicCompareAndSwap32Barrier(1, 0, (int32_t *)&serverFlags->shouldKeepRunning); } - (void)runDOServerForPorts:(NSArray *)ports { @@ -301,8 +284,6 @@ NSAutoreleasePool *pool = [NSAutoreleasePool new]; - OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverFlags->shouldKeepRunning); - @try { // we'll use this to communicate between threads on the localhost localThreadConnection = [[NSConnection alloc] initWithReceivePort:[ports objectAtIndex:0] sendPort:[ports objectAtIndex:1]]; @@ -335,7 +316,27 @@ OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverFlags->serverReady); } - @finally { + @finally {log_method(); + // clean up the connection in the server thread + [localThreadConnection setRootObject:nil]; + + // this frees up the CFMachPorts created in -init + [[localThreadConnection receivePort] invalidate]; + [[localThreadConnection sendPort] invalidate]; + [localThreadConnection invalidate]; + [localThreadConnection release]; + localThreadConnection = nil; + + [serverOnMainThread release]; + serverOnMainThread = nil; + +#ifdef SYNCTEX_FEATURE + if (scanner) { + synctex_scanner_free(scanner); + scanner = NULL; + } +#endif + [pool release]; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit