From 73809519e368dcfe41ad403fec70ac73534ee3f1 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 31 Jul 1998 05:27:17 +0000 Subject: Fri Jul 31 14:00:29 1998 Ross Johnson * cleanup.c (_pthread_destructor_pop): Implement. Removes destructors associated with a key without executing them. (_pthread_destructor_pop_all): Add FIXME comment. * tsd.c (pthread_key_delete): Add call to _pthread_destructor_pop(). --- ChangeLog | 8 ++++++++ cleanup.c | 43 +++++++++++++++++++++++++++++++++++++++++++ tsd.c | 3 ++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3e7956e..e92e60a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jul 31 14:00:29 1998 Ross Johnson + + * cleanup.c (_pthread_destructor_pop): Implement. Removes + destructors associated with a key without executing them. + (_pthread_destructor_pop_all): Add FIXME comment. + + * tsd.c (pthread_key_delete): Add call to _pthread_destructor_pop(). + Fri Jul 31 00:05:45 1998 Ross Johnson * tsd.c (pthread_key_create): Update to properly associate diff --git a/cleanup.c b/cleanup.c index d869ee3..d0daaf1 100644 --- a/cleanup.c +++ b/cleanup.c @@ -117,6 +117,7 @@ _pthread_handler_pop_all(int stack, int execute) } } + int _pthread_destructor_push(void (* routine)(void *), pthread_key_t key) { @@ -126,6 +127,48 @@ _pthread_destructor_push(void (* routine)(void *), pthread_key_t key) key); } + +/* Remove all of the destructors associated with the key. */ +void +_pthread_destructor_pop(pthread_key_t key) +{ + _pthread_handler_node_t ** head; + _pthread_handler_node_t * current; + _pthread_handler_node_t * next; + + head = _PTHREAD_STACK(_PTHREAD_DESTRUCTOR_STACK); + current = *head; + + while (current != NULL) + { + next = current->next; + + /* The destructors associated key is in current->arg. */ + if (current->arg == key) + { + if (current == *head) + { + *head = next; + } + free(current); + } + current = next; + } +} + + +/* Run destructors for all non-NULL key values. + + FIXME: Currently we only run the destructors on the calling + thread's key values. The way I interpret POSIX semantics is that, + for each key that the calling thread has a destructor for, we need + to look at the key values of every thread and run the destructor on + it if the key value is non-NULL. + + The question is: how do we access the key associated values which + are private to other threads? + + */ void _pthread_destructor_pop_all() { diff --git a/tsd.c b/tsd.c index e573d3d..d1d2deb 100644 --- a/tsd.c +++ b/tsd.c @@ -44,7 +44,8 @@ pthread_getspecific(pthread_key_t key) int pthread_key_delete(pthread_key_t key) { - /* FIXME: We must remove any associated destructors here. */ + /* Remove this key's destructors. */ + _pthread_destructor_pop(key); return (TlsFree(key) == FALSE) ? EINVAL : 0; } -- cgit v1.2.3