Move the mailbox to the beginning of the thread and align the

thread so that the context (SSE FPU state) is also aligned.
This commit is contained in:
Daniel Eischen 2003-04-30 15:05:17 +00:00
parent 2c50682195
commit d143dde438
10 changed files with 48 additions and 14 deletions

View File

@ -48,4 +48,7 @@ extern int _thr_getcontext(ucontext_t *);
#define THR_GETCONTEXT(ucp) _thr_getcontext(ucp)
#define THR_SETCONTEXT(ucp) _thr_setcontext(ucp)
#define THR_ALIGNBYTES 15
#define THR_ALIGN(td) (((unsigned)(td) + THR_ALIGNBYTES) & ~THR_ALIGNBYTES)
#endif

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -592,6 +592,12 @@ struct pthread_specific_elem {
* Thread structure.
*/
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;

View File

@ -48,4 +48,7 @@ extern int _thr_getcontext(ucontext_t *);
#define THR_GETCONTEXT(ucp) _thr_getcontext(ucp)
#define THR_SETCONTEXT(ucp) _thr_setcontext(ucp)
#define THR_ALIGNBYTES 15
#define THR_ALIGN(td) (((unsigned)(td) + THR_ALIGNBYTES) & ~THR_ALIGNBYTES)
#endif

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -592,6 +592,12 @@ struct pthread_specific_elem {
* Thread structure.
*/
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;