diff --git a/ChangeLog b/ChangeLog index fa5e7649f..bae94787e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-01-23 Richard Frith-Macdonald + + * Source/NSSocketPort.m: + * Source/NSMessagePort.m: Fixed return form method without unlocking + a lock ... could cause a hang. Also, tidied up add/romve watchers + in runloops. + 2004-01-22 Richard Frith-Macdonald * Headers/Foundation/NSKeyedArchiver.h: Update ivars for unarchiver. diff --git a/Source/NSMessagePort.m b/Source/NSMessagePort.m index 8605c38c1..6b623b47e 100644 --- a/Source/NSMessagePort.m +++ b/Source/NSMessagePort.m @@ -439,11 +439,13 @@ static Class runLoopClass; type: ET_EDESC watcher: self forMode: NSConnectionReplyMode]; + while (valid == YES && state == GS_H_TRYCON && [when timeIntervalSinceNow] > 0) { [l runMode: NSConnectionReplyMode beforeDate: when]; } + [l removeEvent: (void*)(gsaddr)desc type: ET_WDESC forMode: NSConnectionReplyMode @@ -977,6 +979,7 @@ static Class runLoopClass; else { // NSLog(@"No messages to write on 0x%x.", self); + M_UNLOCK(myLock); return; } } @@ -1022,8 +1025,6 @@ static Class runLoopClass; } else { - NSRunLoop *l = [runLoopClass currentRunLoop]; - /* * message completed - remove from list. */ @@ -1033,15 +1034,6 @@ static Class runLoopClass; wData = nil; wItem = 0; [wMsgs removeObjectAtIndex: 0]; - - [l removeEvent: data - type: ET_WDESC - forMode: mode - all: NO]; - [l removeEvent: data - type: ET_EDESC - forMode: mode - all: NO]; } } } @@ -1071,6 +1063,11 @@ static Class runLoopClass; type: ET_WDESC watcher: self forMode: NSConnectionReplyMode]; + [l addEvent: (void*)(gsaddr)desc + type: ET_EDESC + watcher: self + forMode: NSConnectionReplyMode]; + while (valid == YES && [wMsgs indexOfObjectIdenticalTo: components] != NSNotFound && [when timeIntervalSinceNow] > 0) @@ -1079,10 +1076,16 @@ static Class runLoopClass; [l runMode: NSConnectionReplyMode beforeDate: when]; M_LOCK(myLock); } - /* - * NB. We will remove ourself from the run loop when the message send - * is completed, so we don't need to do it here. - */ + + [l removeEvent: (void*)(gsaddr)desc + type: ET_WDESC + forMode: NSConnectionReplyMode + all: NO]; + [l removeEvent: (void*)(gsaddr)desc + type: ET_EDESC + forMode: NSConnectionReplyMode + all: NO]; + if ([wMsgs indexOfObjectIdenticalTo: components] == NSNotFound) { sent = YES; diff --git a/Source/NSSocketPort.m b/Source/NSSocketPort.m index 0abaf84e9..8976739f1 100644 --- a/Source/NSSocketPort.m +++ b/Source/NSSocketPort.m @@ -104,9 +104,9 @@ static BOOL multi_threaded = NO; */ static gsu32 maxDataLength = 10 * 1024 * 1024; -#if 0 -#define M_LOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"lock %@",X); [X lock];} -#define M_UNLOCK(X) {NSDebugMLLog(@"GSTcpHandle",@"unlock %@",X); [X unlock];} +#if 1 +#define M_LOCK(X) {NSDebugMLLog(@"GSTcpHandleLock",@"lock %@ in %@",X,[NSThread currentThread]); [X lock];} +#define M_UNLOCK(X) {NSDebugMLLog(@"GSTcpHandleLock",@"unlock %@ in %@",X,[NSThread currentThread]); [X unlock];} #else #define M_LOCK(X) {[X lock];} #define M_UNLOCK(X) {[X unlock];} @@ -544,11 +544,15 @@ static Class runLoopClass; type: ET_EDESC watcher: self forMode: NSConnectionReplyMode]; + while (valid == YES && state == GS_H_TRYCON && [when timeIntervalSinceNow] > 0) { + M_UNLOCK(myLock); [l runMode: NSConnectionReplyMode beforeDate: when]; + M_LOCK(myLock); } + [l removeEvent: (void*)(gsaddr)desc type: ET_WDESC forMode: NSConnectionReplyMode @@ -1090,6 +1094,7 @@ static Class runLoopClass; else { // NSLog(@"No messages to write on 0x%x.", self); + M_UNLOCK(myLock); return; } } @@ -1131,8 +1136,6 @@ static Class runLoopClass; } else { - NSRunLoop *l = [runLoopClass currentRunLoop]; - /* * message completed - remove from list. */ @@ -1142,15 +1145,6 @@ static Class runLoopClass; wData = nil; wItem = 0; [wMsgs removeObjectAtIndex: 0]; - - [l removeEvent: data - type: ET_WDESC - forMode: mode - all: NO]; - [l removeEvent: data - type: ET_EDESC - forMode: mode - all: NO]; } } } @@ -1180,6 +1174,11 @@ static Class runLoopClass; type: ET_WDESC watcher: self forMode: NSConnectionReplyMode]; + [l addEvent: (void*)(gsaddr)desc + type: ET_EDESC + watcher: self + forMode: NSConnectionReplyMode]; + while (valid == YES && [wMsgs indexOfObjectIdenticalTo: components] != NSNotFound && [when timeIntervalSinceNow] > 0) @@ -1188,10 +1187,16 @@ static Class runLoopClass; [l runMode: NSConnectionReplyMode beforeDate: when]; M_LOCK(myLock); } - /* - * NB. We will remove ourself from the run loop when the message send - * is completed, so we don't need to do it here. - */ + + [l removeEvent: (void*)(gsaddr)desc + type: ET_WDESC + forMode: NSConnectionReplyMode + all: NO]; + [l removeEvent: (void*)(gsaddr)desc + type: ET_EDESC + forMode: NSConnectionReplyMode + all: NO]; + if ([wMsgs indexOfObjectIdenticalTo: components] == NSNotFound) { sent = YES;