Author: gcasa
Date: Mon Oct 24 10:07:49 2016
New Revision: 40170

URL: http://svn.gna.org/viewcvs/gnustep?rev=40170&view=rev
Log:
Fix for lock issue in gui when starting applications on some platforms.  Please 
try and give feedback as this issue is not consistent.  Tested by myself and 
rmottola.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/NSWorkspace.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=40170&r1=40169&r2=40170&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Mon Oct 24 10:07:49 2016
@@ -1,3 +1,12 @@
+2016-10-24 04:03-EDT Gregory John Casamento <[email protected]>
+
+       * Source/NSWorkspace.m: Change to GSLaunchd(...) function to
+       correct lock issue which is ocurring on some systems.  Added
+       a mutex lock to create a critical section and a retry mechanism
+       in case the distributed lock is not released on the first try.
+       This change appears to correct the issue.  Tested by myself and
+       Riccardo.
+
 2016-10-23 Fred Kiefer <[email protected]>
 
        * Source/NSWindow.m (NSMiniWindowView -setImage:): Try to handle
@@ -10,6 +19,7 @@
        * Source/NSLayoutManager.m: Use the pre-computed advancement
        instead of calculating it every time.
 
+>>>>>>> .r40169
 2016-10-22 Fred Kiefer <[email protected]>
 
        * Source/GSLayoutManager.m: Don't try to get the advancement for

Modified: libs/gui/trunk/Source/NSWorkspace.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSWorkspace.m?rev=40170&r1=40169&r2=40170&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSWorkspace.m (original)
+++ libs/gui/trunk/Source/NSWorkspace.m Mon Oct 24 10:07:49 2016
@@ -133,7 +133,11 @@
   NSString                     *name;
   NSDictionary                 *apps = nil;
   BOOL                         modified = NO;
-
+  unsigned                     sleeps = 0;
+  NSLock                        *mlock = nil;
+
+  mlock = [[NSLock alloc] init];
+  [mlock lock]; // start critical section
   if (path == nil)
     {
       path = [NSTemporaryDirectory()
@@ -144,8 +148,6 @@
     }
   if ([lock tryLock] == NO)
     {
-      unsigned sleeps = 0;
-
       /*
        * If the lock is really old ... assume the app has died and break it.
        */
@@ -256,8 +258,40 @@
     {
       [file writeToFile: path atomically: YES];
     }
-  [lock unlock];
-
+
+  NS_DURING
+    {
+      sleeps = 0;
+      [lock unlock];
+    }
+  NS_HANDLER
+    {
+      for (sleeps = 0; sleeps < 10; sleeps++)
+       {
+         NS_DURING
+           {
+             [lock unlock];
+             NSLog(@"Unlocked %@", lock);
+             break;
+           }
+         NS_HANDLER
+           {
+             sleeps++;
+             if (sleeps >= 10)
+               {
+                 NSLog(@"Unable to unlock %@", lock);
+                 break;
+               }      
+             [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 
0.1]];
+             continue;
+           }
+         NS_ENDHANDLER;
+       }
+    }
+  NS_ENDHANDLER;
+  [mlock unlock];  // end critical section
+  [mlock release];
+  
   if (active == YES)
     {
       NSString *activeName = [file objectForKey: @"GSActive"];


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

Reply via email to