mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Try to better handle exception in method in another thread
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38448 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d47a65dc11
commit
c6829f12f7
2 changed files with 36 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2015-04-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSThread.m: If an exception occurs while performing a
|
||||||
|
selector in another thread, catch it and cleanup (and if the
|
||||||
|
caller is waiting, pass the exception back to it).
|
||||||
|
|
||||||
2015-04-01 Wolfgang Lux <wolfgang.lux@gmail.com>
|
2015-04-01 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* configure.ac: Fix comment syntax and use standard operator in
|
* configure.ac: Fix comment syntax and use standard operator in
|
||||||
|
|
|
@ -222,6 +222,8 @@ static NSNotificationCenter *nc = nil;
|
||||||
NSConditionLock *lock; // Not retained.
|
NSConditionLock *lock; // Not retained.
|
||||||
NSArray *modes;
|
NSArray *modes;
|
||||||
BOOL invalidated;
|
BOOL invalidated;
|
||||||
|
@public
|
||||||
|
NSException *exception;
|
||||||
}
|
}
|
||||||
+ (GSPerformHolder*) newForReceiver: (id)r
|
+ (GSPerformHolder*) newForReceiver: (id)r
|
||||||
argument: (id)a
|
argument: (id)a
|
||||||
|
@ -1286,6 +1288,7 @@ GSRunLoopInfoForThread(NSThread *aThread)
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
DESTROY(exception);
|
||||||
DESTROY(receiver);
|
DESTROY(receiver);
|
||||||
DESTROY(argument);
|
DESTROY(argument);
|
||||||
DESTROY(modes);
|
DESTROY(modes);
|
||||||
|
@ -1309,7 +1312,23 @@ GSRunLoopInfoForThread(NSThread *aThread)
|
||||||
}
|
}
|
||||||
threadInfo = GSRunLoopInfoForThread(GSCurrentThread());
|
threadInfo = GSRunLoopInfoForThread(GSCurrentThread());
|
||||||
[threadInfo->loop cancelPerformSelectorsWithTarget: self];
|
[threadInfo->loop cancelPerformSelectorsWithTarget: self];
|
||||||
[receiver performSelector: selector withObject: argument];
|
NS_DURING
|
||||||
|
{
|
||||||
|
[receiver performSelector: selector withObject: argument];
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
ASSIGN(exception, localException);
|
||||||
|
if (nil == lock)
|
||||||
|
{
|
||||||
|
NSLog(@"*** NSRunLoop ignoring exception '%@' (reason '%@') "
|
||||||
|
@"raised during perform in other thread... with receiver %p "
|
||||||
|
@"and selector '%@'",
|
||||||
|
[localException name], [localException reason], receiver,
|
||||||
|
NSStringFromSelector(selector));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
DESTROY(receiver);
|
DESTROY(receiver);
|
||||||
DESTROY(argument);
|
DESTROY(argument);
|
||||||
DESTROY(modes);
|
DESTROY(modes);
|
||||||
|
@ -1452,9 +1471,19 @@ GSRunLoopInfoForThread(NSThread *aThread)
|
||||||
RELEASE(l);
|
RELEASE(l);
|
||||||
if ([h isInvalidated] == YES)
|
if ([h isInvalidated] == YES)
|
||||||
{
|
{
|
||||||
|
RELEASE(h);
|
||||||
[NSException raise: NSInternalInconsistencyException
|
[NSException raise: NSInternalInconsistencyException
|
||||||
format: @"perform on finished thread"];
|
format: @"perform on finished thread"];
|
||||||
|
}
|
||||||
|
/* If we have an exception passed back from the remote thread,
|
||||||
|
* re-raise it.
|
||||||
|
*/
|
||||||
|
if (nil != h->exception)
|
||||||
|
{
|
||||||
|
NSException *e = AUTORELEASE(RETAIN(h->exception));
|
||||||
|
|
||||||
RELEASE(h);
|
RELEASE(h);
|
||||||
|
[e raise];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RELEASE(h);
|
RELEASE(h);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue