From c21915818136c3871b218b253c7df9f7168314b4 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 20 Jun 2014 14:17:17 +0000 Subject: [PATCH] Name server minor safety and performance tweak git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37956 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Source/NSMessagePortNameServer.m | 9 +++++++-- Source/NSSocketPortNameServer.m | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 835eaf328..b5ddf4275 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-06-20 Richard Frith-Macdonald + + * Source/NSSocketPortNameServer.m: + * Source/NSMessagePortNameServer.m: + Maps of ports to names modified to treat the ports as non owned + pointers rather than non retained objects ... so we simply do + pointer comparisons (faster and also safer if we are removing + a port which is being deallocated). + 2014-06-20 Richard Frith-Macdonald * configure.ac: Temporarily add -O0 to turn off optimisation while diff --git a/Source/NSMessagePortNameServer.m b/Source/NSMessagePortNameServer.m index 79fba0275..0bd540d28 100644 --- a/Source/NSMessagePortNameServer.m +++ b/Source/NSMessagePortNameServer.m @@ -133,8 +133,13 @@ static NSMapTable *portToNamesMap; NSEnumerator *files; serverLock = [NSRecursiveLock new]; - portToNamesMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, - NSObjectMapValueCallBacks, 0); + /* Use NSNonOwnedPointerMapKeyCallBacks for the ports used as keys + * since we want as pointer test for equality as we may be doing + * lookup while dealocating the port (in which case the -isEqual: + * method could fail). + */ + portToNamesMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, + NSObjectMapValueCallBacks, 0); [self registerAtExit]; /* It's possible that an old process, with the same process ID as diff --git a/Source/NSSocketPortNameServer.m b/Source/NSSocketPortNameServer.m index f727b3c2e..37a706146 100644 --- a/Source/NSSocketPortNameServer.m +++ b/Source/NSSocketPortNameServer.m @@ -590,7 +590,12 @@ typedef enum { } s = (NSSocketPortNameServer*)NSAllocateObject(self, 0, NSDefaultMallocZone()); - s->_portMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, + /* Use NSNonOwnedPointerMapKeyCallBacks for the ports used as keys + * since we want as pointer test for equality as we may be doing + * lookup while dealocating the port (in which case the -isEqual: + * method could fail). + */ + s->_portMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSObjectMapValueCallBacks, 0); s->_nameMap = NSCreateMapTable(NSObjectMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0);