Author: rfm
Date: Thu May 14 15:47:30 2015
New Revision: 38496

URL: http://svn.gna.org/viewcvs/gnustep?rev=38496&view=rev
Log:
thread safety improvements

Modified:
    libs/ec/trunk/EcProcess.m

Modified: libs/ec/trunk/EcProcess.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/EcProcess.m?rev=38496&r1=38495&r2=38496&view=diff
==============================================================================
--- libs/ec/trunk/EcProcess.m   (original)
+++ libs/ec/trunk/EcProcess.m   Thu May 14 15:47:30 2015
@@ -1399,6 +1399,8 @@
       return;
     }
   name = [name lastPathComponent];
+
+  [self ecDoLock];
   hdl = [cmdLogMap objectForKey: name];
   if (hdl != nil)
     {
@@ -1413,7 +1415,7 @@
       NS_DURING
         [hdl closeFile];
       NS_HANDLER
-      NS_HANDLER
+      NS_ENDHANDLER
 
       /*
        * If the file is empty, remove it, otherwise move to archive directory.
@@ -1444,6 +1446,7 @@
        */
       [cmdLogMap removeObjectForKey: name];
     }
+  [self ecUnLock];
 }
 
 - (NSFileHandle*) cmdLogFile: (NSString*)name
@@ -1457,6 +1460,7 @@
       return nil;
     }
   name = [name lastPathComponent];
+  [self ecDoLock];
   hdl = [cmdLogMap objectForKey: name];
   if (hdl == nil)
     {
@@ -1507,6 +1511,7 @@
        }
       if (hdl == nil)
        {
+          [self ecUnLock];
          return nil;
        }
       /*
@@ -1524,7 +1529,7 @@
               NS_DURING
                 [hdl closeFile];
               NS_HANDLER
-              NS_HANDLER
+              NS_ENDHANDLER
              hdl = [NSFileHandle fileHandleWithStandardError];
            }
        }
@@ -1537,7 +1542,9 @@
          NSLog(@"%@", status);
        }
     }
-  return hdl;
+  [hdl retain];
+  [self ecUnLock];
+  return [hdl autorelease];
 }
 
 - (void) cmdLostConnectionToServer: (NSString*)name
@@ -1794,16 +1801,7 @@
        *       Cause timeout to go off really soon so we will try to
        *       re-establish the link to the server.
        */
-      if (cmdPTimer != nil)
-       {
-         [cmdPTimer invalidate];
-         cmdPTimer = nil;
-       }
-      cmdPTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1
-                                             target: self
-                                           selector: @selector(_timedOut:)
-                                           userInfo: nil
-                                            repeats: NO];
+      [self triggerCmdTimeout];
     }
   else
     {
@@ -1840,9 +1838,12 @@
     }
   else
     {
-      NSEnumerator     *enumerator = [[cmdLogMap allKeys] objectEnumerator];
+      NSEnumerator     *enumerator;
       NSString         *name;
 
+      [self ecDoLock];
+      enumerator = [[cmdLogMap allKeys] objectEnumerator];
+      [self ecUnLock];
       if (subdir == nil)
        {
          NSCalendarDate        *when = [NSCalendarDate date];
@@ -2607,6 +2608,13 @@
 
 - (void) triggerCmdTimeout
 {
+  if (NO == [NSThread isMainThread])
+    {
+      [self performSelectorOnMainThread: _cmd
+                             withObject: nil
+                          waitUntilDone: NO];
+      return;
+    }
   if (cmdPTimer != nil)
     {
       /*
@@ -4448,7 +4456,8 @@
             }
           NS_HANDLER
             {
-              NSLog(@"Exception performing regular timeout: %@", 
localException);
+              NSLog(@"Exception performing regular timeout: %@",
+                localException);
               delay = YES;     // Avoid runaway logging.
             }
           NS_ENDHANDLER


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to