Double locking check added in invalidation.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14535 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-09-24 05:42:32 +00:00
parent 47851f56ed
commit cafea3d3da

View file

@ -681,31 +681,34 @@ static Class runLoopClass;
- (void) invalidate - (void) invalidate
{ {
DO_LOCK(myLock);
if (valid == YES) if (valid == YES)
{ {
NSRunLoop *l; DO_LOCK(myLock);
if (valid == YES)
{
NSRunLoop *l;
valid = NO; valid = NO;
l = [runLoopClass currentRunLoop]; l = [runLoopClass currentRunLoop];
[l removeEvent: (void*)(gsaddr)desc [l removeEvent: (void*)(gsaddr)desc
type: ET_RDESC type: ET_RDESC
forMode: nil forMode: nil
all: YES]; all: YES];
[l removeEvent: (void*)(gsaddr)desc [l removeEvent: (void*)(gsaddr)desc
type: ET_WDESC type: ET_WDESC
forMode: nil forMode: nil
all: YES]; all: YES];
[l removeEvent: (void*)(gsaddr)desc [l removeEvent: (void*)(gsaddr)desc
type: ET_EDESC type: ET_EDESC
forMode: nil forMode: nil
all: YES]; all: YES];
NSDebugMLLog(@"GSTcpHandle", @"invalidated 0x%x in thread 0x%x", NSDebugMLLog(@"GSTcpHandle", @"invalidated 0x%x in thread 0x%x",
self, GSCurrentThread()); self, GSCurrentThread());
[[self recvPort] removeHandle: self]; [[self recvPort] removeHandle: self];
[[self sendPort] removeHandle: self]; [[self sendPort] removeHandle: self];
}
DO_UNLOCK(myLock);
} }
DO_UNLOCK(myLock);
} }
- (BOOL) isValid - (BOOL) isValid
@ -1791,50 +1794,53 @@ static Class tcpPortClass;
- (void) invalidate - (void) invalidate
{ {
DO_LOCK(myLock); if ([self isValid] == YES)
if ([self isValid])
{ {
NSMapTable *thePorts; DO_LOCK(myLock);
NSArray *handleArray;
unsigned i;
[tcpPortLock lock]; if ([self isValid] == YES)
thePorts = NSMapGet(tcpPortMap, (void*)(gsaddr)portNum);
if (thePorts != 0)
{ {
if (listener >= 0) NSMapTable *thePorts;
{ NSArray *handleArray;
(void) close(listener); unsigned i;
listener = -1;
}
NSMapRemove(thePorts, (void*)host);
}
[tcpPortLock unlock];
if (handles != 0) [tcpPortLock lock];
{ thePorts = NSMapGet(tcpPortMap, (void*)(gsaddr)portNum);
handleArray = NSAllMapTableValues(handles); if (thePorts != 0)
i = [handleArray count];
while (i-- > 0)
{ {
GSTcpHandle *handle = [handleArray objectAtIndex: i]; if (listener >= 0)
{
[handle invalidate]; (void) close(listener);
listener = -1;
}
NSMapRemove(thePorts, (void*)host);
} }
/* [tcpPortLock unlock];
* We permit mutual recursive invalidation, so the handles map
* may already have been destroyed.
*/
if (handles != 0) if (handles != 0)
{ {
NSFreeMapTable(handles); handleArray = NSAllMapTableValues(handles);
handles = 0; i = [handleArray count];
while (i-- > 0)
{
GSTcpHandle *handle = [handleArray objectAtIndex: i];
[handle invalidate];
}
/*
* We permit mutual recursive invalidation, so the handles map
* may already have been destroyed.
*/
if (handles != 0)
{
NSFreeMapTable(handles);
handles = 0;
}
} }
[super invalidate];
} }
[super invalidate]; DO_UNLOCK(myLock);
} }
DO_UNLOCK(myLock);
} }
- (BOOL) isEqual: (id)anObject - (BOOL) isEqual: (id)anObject