summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_create.c
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1996-08-20 08:22:01 +0000
committerjulian <julian@FreeBSD.org>1996-08-20 08:22:01 +0000
commit7350d1d3b2ec940c89a2b20f9d09985d9fd9e9d7 (patch)
treeb14348030d1048f8628b798374a8a061a990aae3 /lib/libpthread/thread/thr_create.c
parent60125bd1a9e42a8b02f15396ba886b417c95bbc1 (diff)
downloadFreeBSD-src-7350d1d3b2ec940c89a2b20f9d09985d9fd9e9d7.zip
FreeBSD-src-7350d1d3b2ec940c89a2b20f9d09985d9fd9e9d7.tar.gz
Submitted by: John Birrell <cimaxp1!jb@werple.net.au>
Here are the diffs for libc_r to get it one step closer to P1003.1c These make most of the thread/mutex/condvar structures opaque to the user. There are three functions which have been renamed with _np suffixes because they are extensions to P1003.1c (I did them for JAVA, which needs to suspend/resume threads and also start threads suspended). I've created a new header (pthread_np.h) for the non-POSIX stuff. The egrep tags stuff in /usr/src/lib/libc_r/Makefile that I uncommented doesn't work. I think its best to delete it. I don't think libc_r needs tags anyway, 'cause most of the source is in libc which does have tags. also: Here's the first batch of man pages for the thread functions. The diff to /usr/src/lib/libc_r/Makefile removes some stuff that was inherited from /usr/src/lib/libc/Makefile that should only be done with libc. also: I should have sent this diff with the pthread(3) man page. It allows people to type make -DWANT_LIBC_R world to get libc_r built with the rest of the world. I put this in the pthread(3) man page. The default is still not to build libc_r. also: The diff attached adds a pthread(3) man page to /usr/src/share/man/man3. The idea is that without libc_r installed, this man page will give people enough info to know that they have to build libc_r.
Diffstat (limited to 'lib/libpthread/thread/thr_create.c')
-rw-r--r--lib/libpthread/thread/thr_create.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/libpthread/thread/thr_create.c b/lib/libpthread/thread/thr_create.c
index e6db381..1d57f8a 100644
--- a/lib/libpthread/thread/thr_create.c
+++ b/lib/libpthread/thread/thr_create.c
@@ -49,6 +49,7 @@ _thread_create(pthread_t * thread, const pthread_attr_t * attr,
int ret = 0;
int status;
pthread_t new_thread;
+ pthread_attr_t pattr;
void *stack;
/* Block signals: */
@@ -60,15 +61,17 @@ _thread_create(pthread_t * thread, const pthread_attr_t * attr,
ret = EAGAIN;
} else {
/* Check if default thread attributes are required: */
- if (attr == NULL) {
+ if (attr == NULL || *attr == NULL) {
/* Use the default thread attributes: */
- attr = &pthread_attr_default;
+ pattr = &pthread_attr_default;
+ } else {
+ pattr = *attr;
}
/* Check if a stack was specified in the thread attributes: */
- if ((stack = attr->stackaddr_attr) != NULL) {
+ if ((stack = pattr->stackaddr_attr) != NULL) {
}
/* Allocate memory for the stack: */
- else if ((stack = (void *) malloc(attr->stacksize_attr)) == NULL) {
+ else if ((stack = (void *) malloc(pattr->stacksize_attr)) == NULL) {
/* Insufficient memory to create a thread: */
ret = EAGAIN;
free(new_thread);
@@ -83,7 +86,7 @@ _thread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->stack = stack;
new_thread->start_routine = start_routine;
new_thread->arg = arg;
- if (attr->suspend == PTHREAD_CREATE_SUSPENDED) {
+ if (pattr->suspend == PTHREAD_CREATE_SUSPENDED) {
new_thread->state = PS_SUSPENDED;
} else {
new_thread->state = PS_RUNNING;
@@ -148,19 +151,19 @@ _thread_create(pthread_t * thread, const pthread_attr_t * attr,
/* The stack starts high and builds down: */
#if defined(__FreeBSD__)
- new_thread->saved_jmp_buf[0]._jb[2] = (int) (new_thread->stack + attr->stacksize_attr - sizeof(double));
+ new_thread->saved_jmp_buf[0]._jb[2] = (int) (new_thread->stack + pattr->stacksize_attr - sizeof(double));
#elif defined(__NetBSD__)
#if defined(__alpha)
- new_thread->saved_jmp_buf[4 + R_SP] = (long) new_thread->stack + attr->stacksize_attr - sizeof(double);
+ new_thread->saved_jmp_buf[4 + R_SP] = (long) new_thread->stack + pattr->stacksize_attr - sizeof(double);
#else
- new_thread->saved_jmp_buf[2] = (long) new_thread->stack + attr->stacksize_attr - sizeof(double);
+ new_thread->saved_jmp_buf[2] = (long) new_thread->stack + pattr->stacksize_attr - sizeof(double);
#endif
#else
#error "Don't recognize this operating system!"
#endif
/* Copy the thread attributes: */
- memcpy(&new_thread->attr, attr, sizeof(pthread_attr_t));
+ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr));
/*
* Check if this thread is to inherit the scheduling
OpenPOWER on IntegriCloud