diff options
Diffstat (limited to 'lib/libthr/thread')
-rw-r--r-- | lib/libthr/thread/thr_create.c | 13 | ||||
-rw-r--r-- | lib/libthr/thread/thr_init.c | 3 | ||||
-rw-r--r-- | lib/libthr/thread/thr_private.h | 2 |
3 files changed, 15 insertions, 3 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index 3033421..5b0158d 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -116,7 +116,18 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, new_thread->ctx.uc_stack.ss_sp = new_thread->stack; new_thread->ctx.uc_stack.ss_size = pattr->stacksize_attr; makecontext(&new_thread->ctx, _thread_start, 0); - new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread); + new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread, &ret); + if (ret != 0) { + if (pattr->stackaddr_attr == NULL) { + /* XXX - We really need to decouple from this lock */ + DEAD_LIST_LOCK; + _thread_stack_free(new_thread->stack, + pattr->stacksize_attr, pattr->guardsize_attr); + DEAD_LIST_UNLOCK; + } + free(new_thread); + return (ret); + } /* Copy the thread attributes: */ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 98b0eef..9c334da 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -162,6 +162,7 @@ _thread_init(void) size_t len; int mib[2]; sigset_t set; + int error; struct clockinfo clockinfo; struct sigaction act; @@ -221,7 +222,7 @@ _thread_init(void) memset(pthread, 0, sizeof(struct pthread)); _thread_initial = pthread; - pthread->arch_id = _set_curthread(NULL, pthread); + pthread->arch_id = _set_curthread(NULL, pthread, &error); /* Get our thread id. */ thr_self(&pthread->thr_id); diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index db2bab2..d8e37b4 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -711,7 +711,7 @@ char *ttyname_r(int, char *, size_t); void _cond_wait_backout(pthread_t); int _find_thread(pthread_t); pthread_t _get_curthread(void); -void *_set_curthread(ucontext_t *, struct pthread *); +void *_set_curthread(ucontext_t *, struct pthread *, int *); void _retire_thread(void *arch_id); void *_thread_stack_alloc(size_t, size_t); void _thread_stack_free(void *, size_t, size_t); |