Revision: 3294
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3294&view=rev
Author:   hofman
Date:     2007-12-01 17:09:29 -0800 (Sat, 01 Dec 2007)

Log Message:
-----------
Block DO server in init until it is set up. 

Modified Paths:
--------------
    trunk/SKPDFSynchronizer.h
    trunk/SKPDFSynchronizer.m

Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h   2007-12-01 11:49:04 UTC (rev 3293)
+++ trunk/SKPDFSynchronizer.h   2007-12-02 01:09:29 UTC (rev 3294)
@@ -56,6 +56,7 @@
     NSConnection *localThreadConnection;
     
     volatile int32_t shouldKeepRunning __attribute__ ((aligned (4)));
+    volatile int32_t serverReady __attribute__ ((aligned (4)));
 }
 
 

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2007-12-01 11:49:04 UTC (rev 3293)
+++ trunk/SKPDFSynchronizer.m   2007-12-02 01:09:29 UTC (rev 3294)
@@ -121,10 +121,16 @@
         serverOnServerThread = nil;
        
         shouldKeepRunning = 1;
+        serverReady = 0;
         
         // run a background thread to connect to the remote server
         // this will connect back to the connection we just set up
         [NSThread detachNewThreadSelector:@selector(runDOServerForPorts:) 
toTarget:self withObject:[NSArray arrayWithObjects:port2, port1, nil]];
+        
+        // wait till the server is set up
+        do {
+            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
beforeDate:[NSDate distantFuture]];
+        } while (serverReady == 0 && shouldKeepRunning == 1);
     }
     return self;
 }
@@ -206,14 +212,10 @@
 #pragma mark | Finding
 
 - (void)findLineForLocation:(NSPoint)point inRect:(NSRect)rect 
atPageIndex:(unsigned int)pageIndex {
-    while (shouldKeepRunning && serverOnServerThread == nil)
-        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate 
dateWithTimeIntervalSinceNow:0.1]];
     [serverOnServerThread serverFindLineForLocation:point inRect:rect 
atPageIndex:pageIndex];
 }
 
 - (void)findPageLocationForLine:(int)line inFile:(NSString *)file {
-    while (shouldKeepRunning && serverOnServerThread == nil)
-        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate 
dateWithTimeIntervalSinceNow:0.1]];
     [serverOnServerThread serverFindPageLocationForLine:line inFile:file];
 }
 
@@ -275,6 +277,8 @@
         // handshake, this sets the proxy at the other side
         [serverOnMainThread setLocalServer:self];
         
+        OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverReady);
+        
         NSRunLoop *rl = [NSRunLoop currentRunLoop];
         BOOL didRun;
         
@@ -289,6 +293,8 @@
         NSLog(@"Discarding exception \"[EMAIL PROTECTED]" raised in object 
%@", exception, self);
         // reset the flag so we can start over; shouldn't be necessary
         OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&shouldKeepRunning);
+        // allow the main thread to continue, anyway
+        OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverReady);
     }
     
     @finally {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to