diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-08-04 21:56:52 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-08-04 21:56:52 +0000 |
commit | 4176f14cb11f719a0db22b19c05cae26d2736b67 (patch) | |
tree | b8e02b2c41b25ae4281f84a72406dda46c8bf5aa /lib/librthread | |
parent | 210d7ea72ba678aaf8646ee99b234653db3813a4 (diff) |
Fix caching of stacks allocated with the default attributes.
based on a diff from Christian Schulte (cs at schulte.it)
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread_stack.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/librthread/rthread_stack.c b/lib/librthread/rthread_stack.c index a81e1ad5514..c7ac523150f 100644 --- a/lib/librthread/rthread_stack.c +++ b/lib/librthread/rthread_stack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_stack.c,v 1.7 2012/02/19 04:54:40 guenther Exp $ */ +/* $OpenBSD: rthread_stack.c,v 1.8 2012/08/04 21:56:51 guenther Exp $ */ /* $snafu: rthread_stack.c,v 1.12 2005/01/11 02:45:28 marc Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ @@ -33,15 +33,17 @@ _rthread_alloc_stack(pthread_t thread) size_t guardsize; /* if the request uses the defaults, try to reuse one */ - if (thread->attr.stack_addr != NULL && + if (thread->attr.stack_addr == NULL && thread->attr.stack_size == RTHREAD_STACK_SIZE_DEF && thread->attr.guard_size == _rthread_attr_default.guard_size) { _spinlock(&def_stacks_lock); stack = SLIST_FIRST(&def_stacks); - if (stack != NULL) - _spinunlock(&def_stacks_lock); - if (stack != NULL) + if (stack != NULL) { + SLIST_REMOVE_HEAD(&def_stacks, link); + _spinunlock(&def_stacks_lock); return (stack); + } + _spinunlock(&def_stacks_lock); } /* allocate the stack struct that we'll return */ @@ -112,7 +114,7 @@ _rthread_alloc_stack(pthread_t thread) void _rthread_free_stack(struct stack *stack) { - if (stack->len == RTHREAD_STACK_SIZE_DEF && + if (stack->len == RTHREAD_STACK_SIZE_DEF + stack->guardsize && stack->guardsize == _rthread_attr_default.guard_size) { _spinlock(&def_stacks_lock); SLIST_INSERT_HEAD(&def_stacks, stack, link); |