From a9a7a5e9d63f8a71f1d3dfe0e1ed1a28ab589215 Mon Sep 17 00:00:00 2001 From: jasone Date: Fri, 20 Jul 2001 04:23:11 +0000 Subject: Implement pthread_attr_[gs]etguardsize(). Non-default-size stacks used to be malloc()ed, but they are now allocated using mmap(), just as the default-size stacks are. A separate cache of stacks is kept for non-default-size stacks. Collaboration with: deischen --- lib/libpthread/thread/thr_gc.c | 63 ++++++++---------------------------------- 1 file changed, 12 insertions(+), 51 deletions(-) (limited to 'lib/libpthread/thread/thr_gc.c') diff --git a/lib/libpthread/thread/thr_gc.c b/lib/libpthread/thread/thr_gc.c index 83ff38f..9c93028 100644 --- a/lib/libpthread/thread/thr_gc.c +++ b/lib/libpthread/thread/thr_gc.c @@ -34,13 +34,12 @@ * Garbage collector thread. Frees memory allocated for dead threads. * */ +#include #include #include #include #include #include -#include -#include #include #include "pthread_private.h" @@ -123,39 +122,20 @@ _thread_gc(pthread_addr_t arg) * Check if this thread has detached: */ else if ((pthread->attr.flags & - PTHREAD_DETACHED) != 0) { + PTHREAD_DETACHED) != 0) { /* Remove this thread from the dead list: */ TAILQ_REMOVE(&_dead_list, pthread, dle); /* * Check if the stack was not specified by - * the caller to pthread_create and has not + * the caller to pthread_create() and has not * been destroyed yet: */ if (pthread->attr.stackaddr_attr == NULL && pthread->stack != NULL) { - if (pthread->attr.stacksize_attr - == PTHREAD_STACK_DEFAULT) { - /* - * Default-size stack. Cache - * it: - */ - struct stack *spare_stack; - - spare_stack - = (pthread->stack - + PTHREAD_STACK_DEFAULT - - sizeof(struct stack)); - SLIST_INSERT_HEAD(&_stackq, - spare_stack, - qe); - } else { - /* - * Non-standard stack size. - * free() it outside the locks. - */ - p_stack = pthread->stack; - } + _thread_stack_free(pthread->stack, + pthread->attr.stacksize_attr, + pthread->attr.guardsize_attr); } /* @@ -170,37 +150,18 @@ _thread_gc(pthread_addr_t arg) * not destroy it. * * Check if the stack was not specified by - * the caller to pthread_create and has not + * the caller to pthread_create() and has not * been destroyed yet: */ if (pthread->attr.stackaddr_attr == NULL && pthread->stack != NULL) { - if (pthread->attr.stacksize_attr - == PTHREAD_STACK_DEFAULT) { - /* - * Default-size stack. Cache - * it: - */ - struct stack *spare_stack; + _thread_stack_free(pthread->stack, + pthread->attr.stacksize_attr, + pthread->attr.guardsize_attr); - spare_stack - = (pthread->stack - + PTHREAD_STACK_DEFAULT - - sizeof(struct stack)); - SLIST_INSERT_HEAD(&_stackq, - spare_stack, - qe); - } else { - /* - * Non-standard stack size. - * free() it outside the locks: - */ - p_stack = pthread->stack; - } - /* - * NULL the stack pointer now - * that the memory has been freed: + * NULL the stack pointer now that the + * memory has been freed: */ pthread->stack = NULL; } -- cgit v1.1