mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 16:10:48 +00:00
Fix deadlock issue; make generalPasteboard more efficient
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31539 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
782128949e
commit
7a41cf901f
2 changed files with 34 additions and 6 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2010-10-19 Doug Simons <doug.simons@testplant.com>
|
||||
|
||||
* Source/NSPasteboard.m:
|
||||
Changed lock to recursive to prevent deadlock issue (at least on
|
||||
Windows). Also added missing lock on one access to the dictionary.
|
||||
Improved +generalPasteboard to retain instance as long as possible
|
||||
(previously it would get released with each autorelease pool, which
|
||||
happened multiple times on each call to [NSMenu update] for just
|
||||
one example).
|
||||
|
||||
2010-10-18 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Headers/AppKit/NSWorkspace.h:
|
||||
|
|
|
@ -1058,7 +1058,7 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
|
|||
*/
|
||||
@implementation NSPasteboard
|
||||
|
||||
static NSLock *dictionary_lock = nil;
|
||||
static NSRecursiveLock *dictionary_lock = nil;
|
||||
static NSMutableDictionary *pasteboards = nil;
|
||||
static id<GSPasteboardSvr> the_server = nil;
|
||||
static NSMapTable *mimeMap = NULL;
|
||||
|
@ -1069,7 +1069,20 @@ static NSMapTable *mimeMap = NULL;
|
|||
*/
|
||||
+ (NSPasteboard*) generalPasteboard
|
||||
{
|
||||
return [self pasteboardWithName: NSGeneralPboard];
|
||||
static NSPasteboard *generalPboard = nil;
|
||||
// call pasteboardWithName: every time, to update server conniction if needed
|
||||
NSPasteboard *currentGeneralPboard = [self pasteboardWithName: NSGeneralPboard];
|
||||
if (!generalPboard) // getting it for the first time
|
||||
{
|
||||
// add an extra retain to keep it from being released and recreated in every release pool
|
||||
generalPboard = [currentGeneralPboard retain];
|
||||
}
|
||||
else if (currentGeneralPboard != generalPboard)
|
||||
{
|
||||
[generalPboard release];
|
||||
generalPboard = [currentGeneralPboard retain];
|
||||
}
|
||||
return generalPboard;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
|
@ -1078,7 +1091,7 @@ static NSMapTable *mimeMap = NULL;
|
|||
{
|
||||
// Initial version
|
||||
[self setVersion: 1];
|
||||
dictionary_lock = [[NSLock alloc] init];
|
||||
dictionary_lock = [[NSRecursiveLock alloc] init];
|
||||
pasteboards = [[NSMutableDictionary alloc] initWithCapacity: 8];
|
||||
}
|
||||
}
|
||||
|
@ -1459,7 +1472,9 @@ static NSMapTable *mimeMap = NULL;
|
|||
format: @"Illegal attempt to globally release %@", name];
|
||||
}
|
||||
[target releaseGlobally];
|
||||
[dictionary_lock lock];
|
||||
[pasteboards removeObjectForKey: name];
|
||||
[dictionary_lock unlock];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1490,9 +1505,12 @@ static NSMapTable *mimeMap = NULL;
|
|||
if ([self retainCount] == 2)
|
||||
{
|
||||
[dictionary_lock lock];
|
||||
[super retain];
|
||||
[pasteboards removeObjectForKey: name];
|
||||
[super release];
|
||||
if ([self retainCount] == 2)
|
||||
{
|
||||
[super retain];
|
||||
[pasteboards removeObjectForKey: name];
|
||||
[super release];
|
||||
}
|
||||
[dictionary_lock unlock];
|
||||
}
|
||||
[super release];
|
||||
|
|
Loading…
Reference in a new issue