summaryrefslogtreecommitdiff
path: root/pthread/pt-create.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2014-09-28 23:34:10 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2014-09-28 23:34:10 +0200
commit58a36b39ff9968d203037db496cedd8acbb969c3 (patch)
tree33834ad1c4015a19324c5161065d2420af48447c /pthread/pt-create.c
parentd568cf99fd7e16fa9bdfce995c9318c8176f5dcd (diff)
Fetch stack size from rlimit
* pthread/pt-create.c: Include <hurd/resource.h> (__pthread_create_internal): When `attr''s stacksize is 0, try to get the desired size from the RLIMIT_STACK rlimit before defaulting to PTHREAD_STACK_DEFAULT. * sysdeps/generic/pt-attr.c (__pthread_default_attr): Set stacksize to 0 instead of PTHREAD_STACK_DEFAULT.
Diffstat (limited to 'pthread/pt-create.c')
-rw-r--r--pthread/pt-create.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/pthread/pt-create.c b/pthread/pt-create.c
index 78dd17e..386891e 100644
--- a/pthread/pt-create.c
+++ b/pthread/pt-create.c
@@ -24,6 +24,7 @@
#include <resolv.h>
#include <bits/pt-atomic.h>
+#include <hurd/resource.h>
#include <pt-internal.h>
@@ -92,6 +93,7 @@ __pthread_create_internal (struct __pthread **thread,
struct __pthread *pthread;
const struct __pthread_attr *setup;
sigset_t sigset;
+ size_t stacksize;
/* Allocate a new thread structure. */
err = __pthread_alloc (&pthread);
@@ -101,6 +103,17 @@ __pthread_create_internal (struct __pthread **thread,
/* Use the default attributes if ATTR is NULL. */
setup = attr ? attr : &__pthread_default_attr;
+ stacksize = setup->stacksize;
+ if (!stacksize)
+ {
+ struct rlimit rlim;
+ getrlimit(RLIMIT_STACK, &rlim);
+ if (rlim.rlim_cur != RLIM_INFINITY)
+ stacksize = rlim.rlim_cur;
+ if (!stacksize)
+ stacksize = PTHREAD_STACK_DEFAULT;
+ }
+
/* Initialize the thread state. */
pthread->state = (setup->detachstate == PTHREAD_CREATE_DETACHED
? PTHREAD_DETACHED : PTHREAD_JOINABLE);
@@ -120,7 +133,7 @@ __pthread_create_internal (struct __pthread **thread,
err = __pthread_stack_alloc (&pthread->stackaddr,
((setup->guardsize + __vm_page_size-1)
/ __vm_page_size) * __vm_page_size
- + setup->stacksize);
+ + stacksize);
if (err)
goto failed_stack_alloc;
@@ -128,7 +141,7 @@ __pthread_create_internal (struct __pthread **thread,
pthread->stack = 1;
}
- pthread->stacksize = setup->stacksize;
+ pthread->stacksize = stacksize;
/* Allocate the kernel thread and other required resources. */
err = __pthread_thread_alloc (pthread);
@@ -230,7 +243,7 @@ __pthread_create_internal (struct __pthread **thread,
__pthread_stack_dealloc (pthread->stackaddr,
((setup->guardsize + __vm_page_size-1)
/ __vm_page_size) * __vm_page_size
- + pthread->stacksize);
+ + stacksize);
failed_stack_alloc:
__pthread_dealloc (pthread);
failed: