diff --git a/Headers/Foundation/NSThread.h b/Headers/Foundation/NSThread.h index 36e4070da..6a85f66c9 100644 --- a/Headers/Foundation/NSThread.h +++ b/Headers/Foundation/NSThread.h @@ -52,7 +52,7 @@ extern "C" { NSMutableDictionary *_thread_dictionary; struct autorelease_thread_vars _autorelease_vars; id _gcontext; - void *_reserved; // For mfuture expansion + void *_reserved; // For future expansion } + (NSThread*) currentThread; diff --git a/Source/NSThread.m b/Source/NSThread.m index 2b4c89768..8eb422923 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -853,27 +853,39 @@ gnustep_base_thread_callback(void) - (void) start { - if (_active == NO) + if (_active == YES) { - /* Make sure the notification is posted BEFORE the new thread starts. - */ - gnustep_base_thread_callback(); + [NSException raise: NSInternalInconsistencyException + format: @"[%@-$@] called on active thread", + NSStringFromClass([self class]), + NSStringFromSelector(_cmd)]; + } + if (_cancelled == YES) + { + [NSException raise: NSInternalInconsistencyException + format: @"[%@-$@] called on cancelled thread", + NSStringFromClass([self class]), + NSStringFromSelector(_cmd)]; + } - /* The thread must persist until if finishes executing. - */ - RETAIN(self); + /* Make sure the notification is posted BEFORE the new thread starts. + */ + gnustep_base_thread_callback(); - /* Mark the thread as active whiul it's running. - */ - _active = YES; + /* The thread must persist until it finishes executing. + */ + RETAIN(self); - if (objc_thread_detach(@selector(main), self, nil) == NULL) - { - _active = NO; - RELEASE(self); - [NSException raise: NSInternalInconsistencyException - format: @"Unable to detach thread (unknown error)"]; - } + /* Mark the thread as active whiul it's running. + */ + _active = YES; + + if (objc_thread_detach(@selector(main), self, nil) == NULL) + { + _active = NO; + RELEASE(self); + [NSException raise: NSInternalInconsistencyException + format: @"Unable to detach thread (unknown error)"]; } } diff --git a/Source/NSTimer.m b/Source/NSTimer.m index ff411f09e..5b9513088 100644 --- a/Source/NSTimer.m +++ b/Source/NSTimer.m @@ -196,6 +196,14 @@ static Class NSDate_class; { [self invalidate]; } + if (_target != nil) + { + DESTROY(_target); + } + if (_info != nil) + { + DESTROY(_info); + } RELEASE(_date); [super dealloc]; } @@ -253,14 +261,6 @@ static Class NSDate_class; */ - (void) invalidate { - if (_target != nil) - { - DESTROY(_target); - } - if (_info != nil) - { - DESTROY(_info); - } /* OPENSTEP allows this method to be called multiple times. */ //NSAssert(_invalidated == NO, NSInternalInconsistencyException); _invalidated = YES;