mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +00:00
thread termination fixups
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29461 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8ec647b44d
commit
56f4c389a0
3 changed files with 34 additions and 11 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2010-02-01 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSAutoreleasePool.m:
|
||||||
|
* Source/NSThread.m:
|
||||||
|
Tweaks to try and get default thread correctly terminated on exit.
|
||||||
|
|
||||||
2010-01-30 Fred Kiefer <FredKiefer@gmx.de>
|
2010-01-30 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSPropertyList.m (GSBinaryPLParser -rootObject,
|
* Source/NSPropertyList.m (GSBinaryPLParser -rootObject,
|
||||||
|
|
|
@ -385,14 +385,14 @@ static IMP initImp;
|
||||||
*/
|
*/
|
||||||
while (_child != nil || _released_count > 0)
|
while (_child != nil || _released_count > 0)
|
||||||
{
|
{
|
||||||
volatile struct autorelease_array_list *released = _released_head;
|
volatile struct autorelease_array_list *released;
|
||||||
|
|
||||||
/* If there are NSAutoreleasePool below us in the stack of
|
/* If there are NSAutoreleasePool below us in the stack of
|
||||||
NSAutoreleasePools, then deallocate them also. The (only) way we
|
NSAutoreleasePools, then deallocate them also. The (only) way we
|
||||||
could get in this situation (in correctly written programs, that
|
could get in this situation (in correctly written programs, that
|
||||||
don't release NSAutoreleasePools in weird ways), is if an
|
don't release NSAutoreleasePools in weird ways), is if an
|
||||||
exception threw us up the stack. */
|
exception threw us up the stack. */
|
||||||
if (_child != nil)
|
while (_child != nil)
|
||||||
{
|
{
|
||||||
[_child dealloc];
|
[_child dealloc];
|
||||||
}
|
}
|
||||||
|
@ -401,6 +401,7 @@ static IMP initImp;
|
||||||
* so if we are doing "double_release_check"ing, then
|
* so if we are doing "double_release_check"ing, then
|
||||||
* autoreleaseCountForObject: won't find the object we are currently
|
* autoreleaseCountForObject: won't find the object we are currently
|
||||||
* releasing. */
|
* releasing. */
|
||||||
|
released = _released_head;
|
||||||
while (released != 0)
|
while (released != 0)
|
||||||
{
|
{
|
||||||
id *objects = (id*)(released->objects);
|
id *objects = (id*)(released->objects);
|
||||||
|
@ -457,6 +458,7 @@ static IMP initImp;
|
||||||
NSZoneFree(NSDefaultMallocZone(), a);
|
NSZoneFree(NSDefaultMallocZone(), a);
|
||||||
a = n;
|
a = n;
|
||||||
}
|
}
|
||||||
|
_released = _released_head = 0;
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,12 +475,25 @@ static IMP initImp;
|
||||||
NSAutoreleasePool *pool;
|
NSAutoreleasePool *pool;
|
||||||
|
|
||||||
tv = &(((TInfo)thread)->_autorelease_vars);
|
tv = &(((TInfo)thread)->_autorelease_vars);
|
||||||
|
|
||||||
|
/* First release any objects in the pool... bearing in mind that
|
||||||
|
* releasing any object could cause other objects to be added to
|
||||||
|
* the pool.
|
||||||
|
*/
|
||||||
|
pool = tv->current_pool;
|
||||||
|
while (pool)
|
||||||
|
{
|
||||||
|
[pool emptyPool];
|
||||||
|
pool = pool->_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now free the memory (we have finished usingthe pool).
|
||||||
|
*/
|
||||||
pool = tv->current_pool;
|
pool = tv->current_pool;
|
||||||
while (pool)
|
while (pool)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *p = pool->_parent;
|
NSAutoreleasePool *p = pool->_parent;
|
||||||
|
|
||||||
[pool emptyPool];
|
|
||||||
[pool _reallyDealloc];
|
[pool _reallyDealloc];
|
||||||
pool = p;
|
pool = p;
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,7 +313,14 @@ static pthread_key_t thread_object_key;
|
||||||
*/
|
*/
|
||||||
static void exitedThread(void *thread)
|
static void exitedThread(void *thread)
|
||||||
{
|
{
|
||||||
if (thread != defaultThread)
|
if (thread == defaultThread)
|
||||||
|
{
|
||||||
|
NSThread *t = defaultThread;
|
||||||
|
|
||||||
|
defaultThread = nil;
|
||||||
|
[t dealloc];
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "WARNING thread %p terminated without calling +exit!\n",
|
fprintf(stderr, "WARNING thread %p terminated without calling +exit!\n",
|
||||||
thread);
|
thread);
|
||||||
|
@ -447,6 +454,7 @@ static void setThreadForCurrentThread(NSThread *t)
|
||||||
if (t == nil)
|
if (t == nil)
|
||||||
{
|
{
|
||||||
t = [self new];
|
t = [self new];
|
||||||
|
t->_active = YES;
|
||||||
pthread_setspecific(thread_object_key, t);
|
pthread_setspecific(thread_object_key, t);
|
||||||
[thread_creation_lock unlock];
|
[thread_creation_lock unlock];
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -503,7 +511,7 @@ static void setThreadForCurrentThread(NSThread *t)
|
||||||
userInfo: nil];
|
userInfo: nil];
|
||||||
|
|
||||||
[(GSRunLoopThreadInfo*)t->_runLoopInfo invalidate];
|
[(GSRunLoopThreadInfo*)t->_runLoopInfo invalidate];
|
||||||
|
RELEASE(t);
|
||||||
#if GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
|
#if GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
|
||||||
GC_unregister_my_thread();
|
GC_unregister_my_thread();
|
||||||
#endif
|
#endif
|
||||||
|
@ -632,12 +640,6 @@ static void setThreadForCurrentThread(NSThread *t)
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
if (self == defaultThread)
|
|
||||||
{
|
|
||||||
[self retain];
|
|
||||||
[NSException raise: NSInternalInconsistencyException
|
|
||||||
format: @"Deallocating the default thread is not allowed!"];
|
|
||||||
}
|
|
||||||
if (_active == YES)
|
if (_active == YES)
|
||||||
{
|
{
|
||||||
[NSException raise: NSInternalInconsistencyException
|
[NSException raise: NSInternalInconsistencyException
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue