Add pthread_attr_setstacksize(3) and pthread_attr_getstacksize(3).
This commit is contained in:
parent
e3eba51a94
commit
35037df036
|
@ -12,7 +12,9 @@ CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
OBJS=\
|
OBJS=\
|
||||||
pthread_attr_destroy.o \
|
pthread_attr_destroy.o \
|
||||||
|
pthread_attr_getstacksize.o \
|
||||||
pthread_attr_init.o \
|
pthread_attr_init.o \
|
||||||
|
pthread_attr_setstacksize.o \
|
||||||
pthread_condattr_destroy.o \
|
pthread_condattr_destroy.o \
|
||||||
pthread_condattr_getclock.o \
|
pthread_condattr_getclock.o \
|
||||||
pthread_condattr_init.o \
|
pthread_condattr_init.o \
|
||||||
|
|
|
@ -36,10 +36,12 @@ __BEGIN_DECLS
|
||||||
#if defined(__is_sortix_libpthread)
|
#if defined(__is_sortix_libpthread)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
__SIZE_TYPE__ stack_size;
|
||||||
} __pthread_attr_t;
|
} __pthread_attr_t;
|
||||||
#else
|
#else
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
__SIZE_TYPE__ __pthread_stack_size;
|
||||||
} __pthread_attr_t;
|
} __pthread_attr_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,8 @@ int pthread_attr_destroy(pthread_attr_t*);
|
||||||
/* TODO: pthread_attr_getschedpolicy */
|
/* TODO: pthread_attr_getschedpolicy */
|
||||||
/* TODO: pthread_attr_getscope */
|
/* TODO: pthread_attr_getscope */
|
||||||
/* TODO: pthread_attr_getstack */
|
/* TODO: pthread_attr_getstack */
|
||||||
/* TODO: pthread_attr_getstacksize */
|
int pthread_attr_getstacksize(const pthread_attr_t* __restrict,
|
||||||
|
size_t* __restrict);
|
||||||
int pthread_attr_init(pthread_attr_t*);
|
int pthread_attr_init(pthread_attr_t*);
|
||||||
/* TODO: pthread_attr_setdetachstate */
|
/* TODO: pthread_attr_setdetachstate */
|
||||||
/* TODO: pthread_attr_setguardsize */
|
/* TODO: pthread_attr_setguardsize */
|
||||||
|
@ -202,7 +203,7 @@ int pthread_attr_init(pthread_attr_t*);
|
||||||
/* TODO: pthread_attr_setschedpolicy */
|
/* TODO: pthread_attr_setschedpolicy */
|
||||||
/* TODO: pthread_attr_setscope */
|
/* TODO: pthread_attr_setscope */
|
||||||
/* TODO: pthread_attr_setstack */
|
/* TODO: pthread_attr_setstack */
|
||||||
/* TODO: pthread_attr_setstacksize */
|
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
|
||||||
/* TODO: pthread_barrier_destroy */
|
/* TODO: pthread_barrier_destroy */
|
||||||
/* TODO: pthread_barrier_init */
|
/* TODO: pthread_barrier_init */
|
||||||
/* TODO: pthread_barrier_wait */
|
/* TODO: pthread_barrier_wait */
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||||
|
|
||||||
|
This file is part of Sortix libpthread.
|
||||||
|
|
||||||
|
Sortix libpthread is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
Sortix libpthread is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with Sortix libpthread. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
pthread_attr_getstacksize.c++
|
||||||
|
Gets the requested stack size in a thread attribute object.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
int pthread_attr_getstacksize(const pthread_attr_t* restrict attr,
|
||||||
|
size_t* restrict stack_size_ptr)
|
||||||
|
{
|
||||||
|
*stack_size_ptr = attr->stack_size;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||||
|
|
||||||
This file is part of Sortix libpthread.
|
This file is part of Sortix libpthread.
|
||||||
|
|
||||||
|
@ -25,8 +25,11 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static const unsigned long DEFAULT_STACK_SIZE = 64 * 1024;
|
||||||
|
|
||||||
extern "C" int pthread_attr_init(pthread_attr_t* attr)
|
extern "C" int pthread_attr_init(pthread_attr_t* attr)
|
||||||
{
|
{
|
||||||
memset(attr, 0, sizeof(*attr));
|
memset(attr, 0, sizeof(*attr));
|
||||||
|
attr->stack_size = DEFAULT_STACK_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||||
|
|
||||||
|
This file is part of Sortix libpthread.
|
||||||
|
|
||||||
|
Sortix libpthread is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
Sortix libpthread is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with Sortix libpthread. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
pthread_attr_setstacksize.c++
|
||||||
|
Sets the requested stack size in a thread attribute object.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
extern "C" int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stack_size)
|
||||||
|
{
|
||||||
|
attr->stack_size = stack_size;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -121,8 +121,6 @@ static void setup_thread_state(struct pthread* thread, tforkregs_t* regs)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const unsigned long DEFAULT_STACK_SIZE = 64 * 1024;
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
pthread_mutex_t __pthread_num_threads_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t __pthread_num_threads_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
@ -131,12 +129,19 @@ extern "C"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
int pthread_create(pthread_t* restrict thread_ptr,
|
int pthread_create(pthread_t* restrict thread_ptr,
|
||||||
const pthread_attr_t* restrict /*attr*/,
|
const pthread_attr_t* restrict attr,
|
||||||
void* (*entry_function)(void*),
|
void* (*entry_function)(void*),
|
||||||
void* restrict entry_cookie)
|
void* restrict entry_cookie)
|
||||||
{
|
{
|
||||||
assert(thread_ptr);
|
assert(thread_ptr);
|
||||||
|
|
||||||
|
pthread_attr_t default_attr;
|
||||||
|
if ( !attr )
|
||||||
|
{
|
||||||
|
pthread_attr_init(&default_attr);
|
||||||
|
attr = &default_attr;
|
||||||
|
}
|
||||||
|
|
||||||
struct pthread* self = pthread_self();
|
struct pthread* self = pthread_self();
|
||||||
|
|
||||||
// We can't create a thread local storage copy (and thus a new thread) if
|
// We can't create a thread local storage copy (and thus a new thread) if
|
||||||
|
@ -204,7 +209,7 @@ int pthread_create(pthread_t* restrict thread_ptr,
|
||||||
// Set up a stack for the new thread.
|
// Set up a stack for the new thread.
|
||||||
int stack_prot = PROT_READ | PROT_WRITE;
|
int stack_prot = PROT_READ | PROT_WRITE;
|
||||||
int stack_flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
int stack_flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||||
thread->uthread.stack_size = DEFAULT_STACK_SIZE;
|
thread->uthread.stack_size = attr->stack_size;
|
||||||
thread->uthread.stack_mmap =
|
thread->uthread.stack_mmap =
|
||||||
mmap(NULL, thread->uthread.stack_size, stack_prot, stack_flags, -1, 0);
|
mmap(NULL, thread->uthread.stack_size, stack_prot, stack_flags, -1, 0);
|
||||||
if ( thread->uthread.stack_mmap == MAP_FAILED )
|
if ( thread->uthread.stack_mmap == MAP_FAILED )
|
||||||
|
|
Loading…
Reference in New Issue