From 5629d479c341f7bfaf89489b88f0fc701860ac6f Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 23 Jul 1998 13:34:41 +0000 Subject: * global.c: New. Global data objects declared here. These moved from pthread.h. * pthread.h: Move implementation hidden definitions into implement.h. * implement.h: Move implementation hidden definitions from pthread.h. Add constants to index into the different handler stacks. * cleanup.c (_pthread_handler_push): Simplify args. Restructure. (_pthread_handler_pop): Simplify args. Restructure. (_pthread_handler_pop_all): Simplify args. Restructure. --- cleanup.c | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'cleanup.c') diff --git a/cleanup.c b/cleanup.c index 9ea4316..168b75f 100644 --- a/cleanup.c +++ b/cleanup.c @@ -10,7 +10,7 @@ #include "implement.h" void -_pthread_handler_push(_pthread_handler_node_t ** stacktop, +_pthread_handler_push(int stack, int poporder, void (*routine)(void *), void *arg) @@ -19,6 +19,9 @@ _pthread_handler_push(_pthread_handler_node_t ** stacktop, popped off in the order given by poporder. */ _pthread_handler_node_t * new; _pthread_handler_node_t * next; + _pthread_handler_node_t ** stacktop; + + stacktop = _PTHREAD_STACK(stack); new = (_pthread_handler_node_t *) malloc(sizeof(_pthread_handler_node_t)); @@ -34,7 +37,7 @@ _pthread_handler_push(_pthread_handler_node_t ** stacktop, { /* Add the new node to the start of the list. */ new->next = *stacktop; - stacktop = next; + *stacktop = next; } else { @@ -48,29 +51,35 @@ _pthread_handler_push(_pthread_handler_node_t ** stacktop, else { next = *stacktop; + while (next != NULL) { next = next->next; } + next = new; } } } void -_pthread_handler_pop(_pthread_handler_node_t ** stacktop, - int execute) +_pthread_handler_pop(int stack, int execute) { - _pthread_handler_node_t * handler = *stacktop; + _pthread_handler_node_t ** stacktop; + _pthread_handler_node_t * next; + void (* func)(void *); + void * arg; - if (handler != NULL) - { - void (* func)(void *) = handler->routine; - void * arg = handler->arg; + stacktop = _PTHREAD_STACK(stack); - *stacktop = handler->next; + if (*stacktop != NULL) + { + func = (*stacktop)->routine; + arg = (*stacktop)->arg; + next = (*stacktop)->next; - free(handler); + free(*stacktop); + *stacktop = next; if (execute != 0 && func != NULL) { @@ -80,12 +89,28 @@ _pthread_handler_pop(_pthread_handler_node_t ** stacktop, } void -_pthread_handler_pop_all(_pthread_handler_node_t ** stacktop, - int execute) +_pthread_handler_pop_all(int stack, int execute) { - /* Pop and run all handlers on the given stack. */ + /* Pop and possibly run all handlers on the given stack. */ + _pthread_handler_node_t ** stacktop; + _pthread_handler_node_t * next; + void (* func)(void *); + void * arg; + + stacktop = _PTHREAD_STACK(stack); + while (*stacktop != NULL) { - _pthread_handler_pop(stacktop, execute); + func = (*stacktop)->routine; + arg = (*stacktop)->arg; + next = (*stacktop)->next; + + free(*stacktop); + *stacktop = next; + + if (execute != 0 && func != NULL) + { + (void) func(arg); + } } } -- cgit v1.2.3