Revision: 3301
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3301&view=rev
Author:   hofman
Date:     2007-12-03 01:42:22 -0800 (Mon, 03 Dec 2007)

Log Message:
-----------
Call OSMemoryBarrier before reading thread safe flag set by OSAtomic functions.

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

Modified: trunk/SKPDFSynchronizer.h
===================================================================
--- trunk/SKPDFSynchronizer.h   2007-12-02 21:24:46 UTC (rev 3300)
+++ trunk/SKPDFSynchronizer.h   2007-12-03 09:42:22 UTC (rev 3301)
@@ -56,7 +56,8 @@
     NSConnection *localThreadConnection;
     
     volatile int32_t shouldKeepRunning __attribute__ ((aligned (4)));
-    volatile int32_t serverReady __attribute__ ((aligned (4)));
+    
+    BOOL serverReady;
 }
 
 

Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m   2007-12-02 21:24:46 UTC (rev 3300)
+++ trunk/SKPDFSynchronizer.m   2007-12-03 09:42:22 UTC (rev 3301)
@@ -72,7 +72,7 @@
 @end
 
 @protocol SKPDFSynchronizerMainThread
-- (void)setLocalServer:(byref id)anObject;
+- (oneway void)setLocalServer:(byref id)anObject;
 - (oneway void)serverFoundLine:(int)line inFile:(bycopy NSString *)file;
 - (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned 
int)pageIndex;
 @end
@@ -121,7 +121,7 @@
         serverOnServerThread = nil;
        
         shouldKeepRunning = 1;
-        serverReady = 0;
+        serverReady = NO;
         
         // run a background thread to connect to the remote server
         // this will connect back to the connection we just set up
@@ -130,7 +130,8 @@
         // wait till the server is set up
         do {
             [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
beforeDate:[NSDate distantFuture]];
-        } while (serverReady == 0 && shouldKeepRunning == 1);
+            OSMemoryBarrier();
+        } while (serverReady == NO && shouldKeepRunning == 1);
     }
     return self;
 }
@@ -222,19 +223,22 @@
 #pragma mark Main thread
 #pragma mark | DO server
 
-- (void)setLocalServer:(byref id)anObject {
+- (oneway void)setLocalServer:(byref id)anObject {
     [anObject setProtocolForProxy:@protocol(SKPDFSynchronizerServerThread)];
     serverOnServerThread = [anObject retain];
+    serverReady = YES;
 }
 
 #pragma mark | Finding
 
 - (oneway void)serverFoundLine:(int)line inFile:(bycopy NSString *)file {
+    OSMemoryBarrier();
     if (shouldKeepRunning && [delegate 
respondsToSelector:@selector(synchronizer:foundLine:inFile:)])
         [delegate synchronizer:self foundLine:line inFile:file];
 }
 
 - (oneway void)serverFoundLocation:(NSPoint)point atPageIndex:(unsigned 
int)pageIndex {
+    OSMemoryBarrier();
     if (shouldKeepRunning && [delegate 
respondsToSelector:@selector(synchronizer:foundLocation:atPageIndex:)])
         [delegate synchronizer:self foundLocation:point atPageIndex:pageIndex];
 }
@@ -277,8 +281,6 @@
         // handshake, this sets the proxy at the other side
         [serverOnMainThread setLocalServer:self];
         
-        OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t *)&serverReady);
-        
         NSRunLoop *rl = [NSRunLoop currentRunLoop];
         BOOL didRun;
         
@@ -287,6 +289,7 @@
             [pool release];
             pool = [NSAutoreleasePool new];
             didRun = [rl runMode:NSDefaultRunLoopMode beforeDate:[NSDate 
distantFuture]];
+            OSMemoryBarrier();
         } while (shouldKeepRunning == 1 && didRun);
     }
     @catch(id exception) {
@@ -370,6 +373,7 @@
     
     [scanner scanCharactersFromSet:[NSCharacterSet newlineCharacterSet] 
intoString:NULL];
     
+    OSMemoryBarrier();
     while (shouldKeepRunning && [scanner scanCharacter:&ch]) {
         
         if (ch == 'l') {
@@ -418,6 +422,8 @@
         
         [scanner scanUpToCharactersFromSet:[NSCharacterSet 
newlineCharacterSet] intoString:NULL];
         [scanner scanCharactersFromSet:[NSCharacterSet newlineCharacterSet] 
intoString:NULL];
+        
+        OSMemoryBarrier();
     }
     
     [scanner release];
@@ -431,7 +437,10 @@
     [pages makeObjectsPerformSelector:@selector(sortUsingDescriptors:)
                            withObject:[NSArray 
arrayWithObjects:ySortDescriptor, xSortDescriptor, nil]];
     
-    return shouldKeepRunning;
+    OSMemoryBarrier();
+    BOOL returnValue = shouldKeepRunning == 1;
+
+    return returnValue;
 }
 
 - (oneway void)serverFindLineForLocation:(NSPoint)point inRect:(NSRect)rect 
atPageIndex:(unsigned int)pageIndex {
@@ -439,6 +448,7 @@
     NSString *foundFile = nil;
     NSDictionary *record = nil;
     
+    OSMemoryBarrier();
     if (shouldKeepRunning && [self parsePdfsyncFileIfNeeded] && pageIndex < 
[pages count]) {
         
         NSDictionary *beforeRecord = nil;
@@ -496,8 +506,10 @@
             foundFile = [record objectForKey:@"file"];
         }
         
+        OSMemoryBarrier();
     }
     
+    OSMemoryBarrier();
     if (shouldKeepRunning)
         [serverOnMainThread serverFoundLine:foundLine inFile:foundFile];
 }
@@ -507,6 +519,7 @@
     NSPoint foundPoint = NSZeroPoint;
     NSDictionary *record = nil;
     
+    OSMemoryBarrier();
     if (shouldKeepRunning && file && [self parsePdfsyncFileIfNeeded] && [lines 
objectForKey:file]) {
         
         NSDictionary *beforeRecord = nil;
@@ -548,8 +561,11 @@
             foundPageIndex = [[record objectForKey:@"page"] unsignedIntValue];
             foundPoint = NSMakePoint([[record objectForKey:@"x"] floatValue], 
[[record objectForKey:@"y"] floatValue]);
         }
+        
+        OSMemoryBarrier();
     }
     
+    OSMemoryBarrier();
     if (shouldKeepRunning)
         [serverOnMainThread serverFoundLocation:foundPoint 
atPageIndex:foundPageIndex];
 }


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