summaryrefslogtreecommitdiff
path: root/cleanup.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-07-23 13:34:41 +0000
committerrpj <rpj>1998-07-23 13:34:41 +0000
commit5629d479c341f7bfaf89489b88f0fc701860ac6f (patch)
tree42c8f2719b617b8db2e6c611daf00db04304c757 /cleanup.c
parentf33f4460f9de9c2d2ae6f3bf05caed391c6ad485 (diff)
* 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.
Diffstat (limited to 'cleanup.c')
-rw-r--r--cleanup.c55
1 files changed, 40 insertions, 15 deletions
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);
+ }
}
}