pthread: implement stacksize attribute

Issue #2583.
This commit is contained in:
Josef Söntgen 2017-11-23 14:33:31 +01:00 committed by Christian Helmuth
parent f36bc80bd7
commit 86c1f65dfe
3 changed files with 21 additions and 2 deletions

View File

@ -214,6 +214,21 @@ extern "C" {
}
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
{
if (!attr || !*attr)
return EINVAL;
if (stacksize > (Thread::stack_virtual_size() - 4 * 4096) ||
stacksize < 4096)
return EINVAL;
(*attr)->stack_size = Genode::align_addr(stacksize, 12);
return 0;
}
int pthread_attr_getstack(const pthread_attr_t *attr,
void **stackaddr,
::size_t *stacksize)

View File

@ -48,8 +48,9 @@ extern "C" {
struct pthread_attr
{
pthread_t pthread;
size_t stack_size;
pthread_attr() : pthread(0) { }
pthread_attr() : pthread(0), stack_size(0) { }
};

View File

@ -30,8 +30,11 @@ extern "C"
/* cleanup threads which tried to self-destruct */
pthread_cleanup();
size_t const stack_size = (attr && *attr && (*attr)->stack_size)
? (*attr)->stack_size : STACK_SIZE;
pthread_t thread_obj = new pthread(attr ? *attr : 0, start_routine,
arg, STACK_SIZE, "pthread", nullptr,
arg, stack_size, "pthread", nullptr,
Genode::Affinity::Location());
if (!thread_obj)