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.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@40170 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2016-10-24 08:07:49 +00:00
parent 2f2bda5aa4
commit 7ea5efb7eb
2 changed files with 47 additions and 3 deletions

View file

@ -133,7 +133,11 @@ static id GSLaunched(NSNotification *notification, BOOL active)
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 @@ static id GSLaunched(NSNotification *notification, BOOL active)
}
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 @@ static id GSLaunched(NSNotification *notification, BOOL active)
{
[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"];