diff options
Diffstat (limited to 'lib/libpthread/thread')
-rw-r--r-- | lib/libpthread/thread/thr_create.c | 3 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_init.c | 3 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_kern.c | 12 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_private.h | 10 |
4 files changed, 21 insertions, 7 deletions
diff --git a/lib/libpthread/thread/thr_create.c b/lib/libpthread/thread/thr_create.c index 4c65d3c..0c9edbd 100644 --- a/lib/libpthread/thread/thr_create.c +++ b/lib/libpthread/thread/thr_create.c @@ -97,6 +97,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, struct pthread *curthread, *new_thread; struct kse *kse = NULL; struct kse_group *kseg = NULL; + void *p; kse_critical_t crit; int i; int ret = 0; @@ -123,7 +124,9 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, ret = EAGAIN; } else { /* Initialize the thread structure: */ + p = new_thread->alloc_addr; memset(new_thread, 0, sizeof(struct pthread)); + new_thread->alloc_addr = p; /* Check if default thread attributes are required: */ if (attr == NULL || *attr == NULL) diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c index d43adf5..f06df6c 100644 --- a/lib/libpthread/thread/thr_init.c +++ b/lib/libpthread/thread/thr_init.c @@ -311,10 +311,13 @@ _libpthread_init(struct pthread *curthread) static void init_main_thread(struct pthread *thread) { + void *p; int i; /* Zero the initial thread structure. */ + p = thread->alloc_addr; memset(thread, 0, sizeof(struct pthread)); + thread->alloc_addr = p; /* Setup the thread attributes. */ thread->attr = _pthread_attr_default; diff --git a/lib/libpthread/thread/thr_kern.c b/lib/libpthread/thread/thr_kern.c index a153a4d..54d9dd7 100644 --- a/lib/libpthread/thread/thr_kern.c +++ b/lib/libpthread/thread/thr_kern.c @@ -2019,6 +2019,7 @@ struct pthread * _thr_alloc(struct pthread *curthread) { kse_critical_t crit; + void *p; struct pthread *thread = NULL; if (curthread != NULL) { @@ -2035,8 +2036,13 @@ _thr_alloc(struct pthread *curthread) _kse_critical_leave(crit); } } - if (thread == NULL) - thread = (struct pthread *)malloc(sizeof(struct pthread)); + if (thread == NULL) { + p = malloc(sizeof(struct pthread) + THR_ALIGNBYTES); + if (p != NULL) { + thread = (struct pthread *)THR_ALIGN(p); + thread->alloc_addr = p; + } + } return (thread); } @@ -2052,7 +2058,7 @@ _thr_free(struct pthread *curthread, struct pthread *thread) _lockuser_destroy(&thread->lockusers[i]); } _lock_destroy(&thread->lock); - free(thread); + free(thread->alloc_addr); } else { crit = _kse_critical_enter(); diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h index 4d43242..22d2445 100644 --- a/lib/libpthread/thread/thr_private.h +++ b/lib/libpthread/thread/thr_private.h @@ -593,6 +593,12 @@ struct pthread_specific_elem { */ struct pthread { /* + * Thread mailbox is first so it cal be aligned properly. + */ + struct kse_thr_mailbox tmbx; + void *alloc_addr; /* real address (unaligned) */ + + /* * Magic value to help recognize a valid thread structure * from an invalid one: */ @@ -626,10 +632,6 @@ struct pthread { void *arg; struct pthread_attr attr; - /* - * Thread mailbox. - */ - struct kse_thr_mailbox tmbx; int active; /* thread running */ int blocked; /* thread blocked in kernel */ int need_switchout; |