thread unregistering fixup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30174 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-04-16 18:18:43 +00:00
parent 18a3ed0332
commit adc93a3a78
2 changed files with 41 additions and 50 deletions

View file

@ -1,7 +1,12 @@
2010-04-16 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSThread.m: Fix unregistering of threads to properly clean
up and deallocate, avoiding descriptor and memory leak.
2010-04-15 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSConnection.m: when decoding a pointer to an object, autorelease
the object to avoid a leak.
* Source/NSConnection.m: when decoding a pointer to an object,
autorelease the object to avoid a leak.
2010-04-14 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -433,12 +433,41 @@ gnustep_base_thread_callback(void)
@implementation NSThread
static void setThreadForCurrentThread(NSThread *t)
static void
setThreadForCurrentThread(NSThread *t)
{
pthread_setspecific(thread_object_key, t);
gnustep_base_thread_callback();
}
static void
unregisterActiveThread(NSThread *thread)
{
if (thread->_active == YES)
{
/*
* Set the thread to be inactive to avoid any possibility of recursion.
*/
thread->_active = NO;
thread->_finished = YES;
/*
* Let observers know this thread is exiting.
*/
if (nc == nil)
{
nc = RETAIN([NSNotificationCenter defaultCenter]);
}
[nc postNotificationName: NSThreadWillExitNotification
object: thread
userInfo: nil];
[(GSRunLoopThreadInfo*)thread->_runLoopInfo invalidate];
[thread release];
pthread_setspecific(thread_object_key, nil);
}
}
+ (NSArray*) callStackReturnAddresses
{
NSMutableArray *stack = GSPrivateStackAddresses();
@ -496,29 +525,8 @@ static void setThreadForCurrentThread(NSThread *t)
t = GSCurrentThread();
if (t->_active == YES)
{
/*
* Set the thread to be inactive to avoid any possibility of recursion.
*/
t->_active = NO;
t->_finished = YES;
unregisterActiveThread (t);
/*
* Let observers know this thread is exiting.
*/
if (nc == nil)
{
nc = RETAIN([NSNotificationCenter defaultCenter]);
}
[nc postNotificationName: NSThreadWillExitNotification
object: t
userInfo: nil];
[(GSRunLoopThreadInfo*)t->_runLoopInfo invalidate];
RELEASE(t);
#if GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
GC_unregister_my_thread();
#endif
pthread_setspecific(thread_object_key, nil);
if (t == defaultThread || defaultThread == nil)
{
/* For the default thread, we exit the process.
@ -1300,34 +1308,12 @@ GSRegisterCurrentThread (void)
* Calling this function causes a
* <code>NSThreadWillExitNotification</code>
* to be sent out, and destroys the GNUstep NSThread object
* associated with the thread.
* associated with the thread (like [NSThread+exit]) but does
* not exit the underlying thread.
* </p>
*/
void
GSUnregisterCurrentThread (void)
{
NSThread *thread;
thread = GSCurrentThread();
if (thread->_active == YES)
{
/*
* Set the thread to be inactive to avoid any possibility of recursion.
*/
thread->_active = NO;
/*
* Let observers know this thread is exiting.
*/
if (nc == nil)
{
nc = RETAIN([NSNotificationCenter defaultCenter]);
}
[nc postNotificationName: NSThreadWillExitNotification
object: thread
userInfo: nil];
pthread_setspecific(thread_object_key, nil);
}
unregisterActiveThread(GSCurrentThread());
}