summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-10-24 11:44:52 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-10-24 11:44:52 +0200
commit714413a7694ff534855e9e5904899695eac6c9bb (patch)
treeb80a3bdd220b5f6978009ac1459272e1c9b8aa45
parent959f7365fccd1c89be9938c2655eba9122171e6a (diff)
Really use user-provided stack
* pthread/pt-create.c (__pthread_create_internal): When the user provides a `stackaddr`, use it instead of allocating a stack. * pthread/pt-detach.c (pthread_detach): Only deallocate the stack when it was allocated by libpthread. * pthread/pt-join.c (pthread_join): Likewise.
-rw-r--r--pthread/pt-create.c18
-rw-r--r--pthread/pt-detach.c8
-rw-r--r--pthread/pt-join.c8
3 files changed, 22 insertions, 12 deletions
diff --git a/pthread/pt-create.c b/pthread/pt-create.c
index 723aa81..fd6800f 100644
--- a/pthread/pt-create.c
+++ b/pthread/pt-create.c
@@ -129,13 +129,19 @@ __pthread_create_internal (struct __pthread **thread,
}
else
{
- err = __pthread_stack_alloc (&pthread->stackaddr,
- setup->stacksize);
- if (err)
- goto failed_stack_alloc;
-
pthread->stacksize = setup->stacksize;
- pthread->stack = 1;
+
+ if (setup->stackaddr)
+ pthread->stackaddr = setup->stackaddr;
+ else
+ {
+ err = __pthread_stack_alloc (&pthread->stackaddr,
+ setup->stacksize);
+ if (err)
+ goto failed_stack_alloc;
+
+ pthread->stack = 1;
+ }
}
/* Allocate the kernel thread and other required resources. */
diff --git a/pthread/pt-detach.c b/pthread/pt-detach.c
index 1e42c45..4ed8d2c 100644
--- a/pthread/pt-detach.c
+++ b/pthread/pt-detach.c
@@ -66,9 +66,11 @@ pthread_detach (pthread_t thread)
/* Destroy the stack, the kernel resources and the control
block. */
- assert (pthread->stack);
- __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
- pthread->stack = 0;
+ if (pthread->stack)
+ {
+ __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
+ pthread->stack = 0;
+ }
__pthread_thread_dealloc (pthread);
diff --git a/pthread/pt-join.c b/pthread/pt-join.c
index 8bd2c6c..417f433 100644
--- a/pthread/pt-join.c
+++ b/pthread/pt-join.c
@@ -64,9 +64,11 @@ pthread_join (pthread_t thread, void **status)
/* Destroy the stack, the kernel resources and the control
block. */
- assert (pthread->stack);
- __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
- pthread->stack = 0;
+ if (pthread->stack)
+ {
+ __pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
+ pthread->stack = 0;
+ }
__pthread_thread_dealloc (pthread);