From 40cf527fe65e12a745ca7b981676da1fb691eee6 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 19 Jul 1998 16:48:18 +0000 Subject: Mon Jul 20 02:31:05 1998 Ross Johnson * private.c (_pthread_getthreadindex): Implement. * pthread.h: Add application static data dependent on _PTHREADS_BUILD_DLL define. This is needed to avoid allocating non-sharable static data within the pthread DLL. * implement.h: Add _pthread_cleanup_stack_t, _pthread_cleanup_node_t and _PTHREAD_HASH_INDEX. * exit.c (pthread_exit): Begin work on cleanup and de-allocate thread-private storage. * create.c (pthread_create): Add thread to thread table. Keep a thread-private copy of the attributes with default values filled in when necessary. Same for the cleanup stack. Make pthread_create C run-time library friendly by using _beginthreadex() instead of CreateThread(). Fix error returns. Sun Jul 19 16:26:23 1998 Ross Johnson * implement.h: Rename pthreads_thread_count to _pthread_threads_count. Create _pthread_threads_thread_t struct to keep thread specific data. * create.c: Rename pthreads_thread_count to _pthread_threads_count. (pthread_create): Handle errors from CreateThread(). --- exit.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'exit.c') diff --git a/exit.c b/exit.c index 5212854..a0b3b50 100644 --- a/exit.c +++ b/exit.c @@ -15,6 +15,30 @@ pthread_exit(void * value) strict POSIX conformance. We must add code here later which deals with executing cleanup handlers and such. For now, the following is mostly correct: */ + int t; - ExitThread((DWORD) value); + t = _pthread_getthreadindex(pthread_self()); + handler = _pthread_threads_table[t]->cleanupstack->first; + + /* Run all the cleanup handlers */ + while (handler != NULL) { + void (* func)(void *); + void * arg; + _pthread_cleanup_node_t * next; + + func = handler->routine; + arg = handler->arg; + _pthread_threads_table[t]->cleanupstack->first = next = handler->next; + free(handler); + (void) func(arg); + } + + /* CRITICAL SECTION */ + pthread_mutex_lock(&_pthread_count_mutex); + free(_pthread_threads_table[t]->attr); + _pthread_threads_table[t]->thread = NULL; + pthread_mutex_unlock(&_pthread_count_mutex); + /* END CRITICAL SECTION */ + + _endthreadex((DWORD) value); } -- cgit v1.2.3