From 317c73af1d3142947ba5f5d2f5251c4a34abda52 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Wed, 4 May 2005 16:04:06 +0000 Subject: libpthread/ 2005-05-04 Neal H. Walfield * Makefile (SRCS): Add pt-thread_dealloc.c. * sysdeps/mach/pt-thread-dealloc.c: New file. * pthread/pt-internal.h (__pthread_thread_dealloc): New declaration. (__pthread_thread_halt): Add parameter NEED_DEALLOC. Update callers. * sysdeps/mach/pt-thread-halt.c (__pthread_thread_halt): Respect new NEED_DEALLOC parameter. Move code which deallocates kernel resources from here ... * sysdeps/mach/pt-thread-dealloc.c (__pthread_thread_dealloc): ...to here. * pthread/pt-create.c (__pthread_create_internal): Call __pthread_thread_dealloc on failure. * pthread/pt-exit.c (pthread_exit): Call __pthread_thread_dealloc. * sysdeps/mach/pt-thread-alloc.c (create_wakeupmsg): Call __mach_port_destroy to deallocate the receive right. __mach_port_deallocate won't do it. * pthread/pt-detach.c (pthread_detach): Don't call __pthread_thread_halt a second time. * sysdeps/mach/hurd/pt-sysdep.c (_cthread_init_routine): Fix declaration. (init_routine): Update declaration and remove gratuitous cast. --- pthread/pt-exit.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'pthread/pt-exit.c') diff --git a/pthread/pt-exit.c b/pthread/pt-exit.c index fb9e97c0..7484ffd1 100644 --- a/pthread/pt-exit.c +++ b/pthread/pt-exit.c @@ -1,5 +1,5 @@ /* Thread termination. - Copyright (C) 2000,02 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -35,6 +35,7 @@ pthread_exit (void *status) struct __pthread *self = _pthread_self (); struct __pthread_cancelation_handler **handlers; int oldstate; + int need_dealloc; /* Run any cancelation handlers. According to POSIX, the cancellation cleanup handlers should be called with cancellation @@ -69,10 +70,13 @@ pthread_exit (void *status) if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending) status = PTHREAD_CANCELED; + __pthread_thread_dealloc (self); + switch (self->state) { default: - assert (! "This cannot happen!"); + assert (! "Consistency error: unexpected self->state"); + abort (); break; case PTHREAD_DETACHED: @@ -82,7 +86,7 @@ pthread_exit (void *status) deallocate our own stack. However, it will eventually be reused when this thread structure is recycled. */ __pthread_mutex_unlock (&self->state_lock); - __pthread_dealloc (self); + need_dealloc = 1; break; @@ -99,6 +103,7 @@ pthread_exit (void *status) waiting to join us. */ pthread_cond_broadcast (&self->state_cond); __pthread_mutex_unlock (&self->state_lock); + need_dealloc = 0; break; } @@ -108,7 +113,7 @@ pthread_exit (void *status) This means that before freeing any resources, such a thread should make sure that this thread is really halted. */ - __pthread_thread_halt (self); + __pthread_thread_halt (self, need_dealloc); /* NOTREACHED */ abort (); -- cgit v1.2.3