mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-24 20:49:13 +00:00
Create lock in +initialize so it can safely be used to prevent threads in the
same process from trying to obtain the distributed lock concurrently. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@40174 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9a8495c0d6
commit
1a74105054
1 changed files with 4 additions and 4 deletions
|
@ -111,6 +111,7 @@ static NSImage *multipleFiles = nil;
|
|||
static NSImage *unknownApplication = nil;
|
||||
static NSImage *unknownTool = nil;
|
||||
|
||||
NSLock *mlock = nil;
|
||||
|
||||
static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
|
||||
static NSString *GSWorkspacePreferencesChanged =
|
||||
|
@ -134,9 +135,7 @@ static id GSLaunched(NSNotification *notification, BOOL active)
|
|||
NSDictionary *apps = nil;
|
||||
BOOL modified = NO;
|
||||
unsigned sleeps = 0;
|
||||
NSLock *mlock = nil;
|
||||
|
||||
mlock = [[NSLock alloc] init];
|
||||
[mlock lock]; // start critical section
|
||||
if (path == nil)
|
||||
{
|
||||
|
@ -177,6 +176,7 @@ static id GSLaunched(NSNotification *notification, BOOL active)
|
|||
}
|
||||
if (sleeps >= 10)
|
||||
{
|
||||
[mlock unlock];
|
||||
NSLog(@"Unable to obtain lock %@", lock);
|
||||
return nil;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ static id GSLaunched(NSNotification *notification, BOOL active)
|
|||
NSLog(@"Unable to unlock %@", lock);
|
||||
break;
|
||||
}
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
|
||||
[NSThread sleepForTimeInterval: 0.1];
|
||||
continue;
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
|
@ -290,7 +290,6 @@ static id GSLaunched(NSNotification *notification, BOOL active)
|
|||
}
|
||||
NS_ENDHANDLER;
|
||||
[mlock unlock]; // end critical section
|
||||
[mlock release];
|
||||
|
||||
if (active == YES)
|
||||
{
|
||||
|
@ -595,6 +594,7 @@ static NSDictionary *urlPreferences = nil;
|
|||
}
|
||||
|
||||
beenHere = YES;
|
||||
mlock = [NSLock new];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue