From f33f4460f9de9c2d2ae6f3bf05caed391c6ad485 Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 22 Jul 1998 16:42:53 +0000 Subject: Wed Jul 22 00:16:22 1998 Ross Johnson * attr.c, implement.h, pthread.h, ChangeLog: Resolve CVS merge conflicts. * private.c (_pthread_find_thread_entry): Changes to return type to support leaner _pthread_threads_table[] which now only stores _pthread_thread_thread_t *. (_pthread_new_thread_entry): Internal changes. (_pthread_delete_thread_entry): Internal changes to avoid contention. Calling routines changed accordingly. * pthread.h: Modified cleanup macros to use new generic push and pop. Added destructor and atfork stacks to _pthread_threads_thread_t. * cleanup.c (_pthread_handler_push, _pthread_handler_pop, _pthread_handler_pop_all): Renamed cleanup push and pop routines and made generic to handle destructors and atfork handlers as well. * create.c (_pthread_start_call): New function is a wrapper for all new threads. It allows us to do some cleanup when the thread returns, ie. that is otherwise only done if the thread is cancelled. * exit.c (_pthread_vacuum): New function contains code from pthread_exit() that we need in the new _pthread_start_call() as well. * implement.h: Various additions and minor changes. * pthread.h: Various additions and minor changes. Change cleanup handler macros to use generic handler push and pop functions. * attr.c: Minor mods to all functions. (is_attr): Implemented missing function. * create.c (pthread_create): More clean up. * private.c (_pthread_find_thread_entry): Implement. (_pthread_delete_thread_entry): Implement. (_pthread_new_thread_entry): Implement. These functions manipulate the implementations internal thread table and are part of general code cleanup and modularisation. They replace _pthread_getthreadindex() which was removed. * exit.c (pthread_exit): Changed to use the new code above. * pthread.h: Add cancelability constants. Update comments. --- exit.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'exit.c') diff --git a/exit.c b/exit.c index 0778fc2..a9c352c 100644 --- a/exit.c +++ b/exit.c @@ -12,25 +12,30 @@ #include "implement.h" void -pthread_exit(void * value) +_pthread_vacuum(void) { - int t; - - t = _pthread_getthreadindex(pthread_self()); + /* This function can be called from pthread_exit(), or from + _pthread_start_call() in which case cleanupstack should be + empty but destructorstack still needs to be run. */ + _pthread_threads_thread_t * this; - /* Run all the cleanup handlers */ - _pthread_do_cancellation(t); + this = *_PTHREAD_THIS; - /* CRITICAL SECTION */ - pthread_mutex_lock(&_pthread_count_mutex); + /* Run all the handlers. */ + _pthread_handler_pop_all(&(this->cleanupstack), _PTHREAD_HANDLER_EXECUTE); + _pthread_handler_pop_all(&(this->destructorstack), _PTHREAD_HANDLER_EXECUTE); - /* Frees attr and cleanupstack */ - free(_pthread_threads_table[t]->attr); + /* Pop any atfork handlers to free storage. */ + _pthread_handler_pop_all(&(this->forkprepare), _PTHREAD_HANDLER_NOEXECUTE); + _pthread_handler_pop_all(&(this->forkparent), _PTHREAD_HANDLER_NOEXECUTE); + _pthread_handler_pop_all(&(this->forkchild), _PTHREAD_HANDLER_NOEXECUTE); - _pthread_threads_table[t]->thread = NULL; - - pthread_mutex_unlock(&_pthread_count_mutex); - /* END CRITICAL SECTION */ + _pthread_delete_thread_entry(NULL); +} +void +pthread_exit(void * value) +{ + _pthread_vacuum(); _endthreadex((DWORD) value); } -- cgit v1.2.3