thr_create.c (113658) | thr_create.c (113661) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com> |
|
2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 3 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
32 * $FreeBSD: head/lib/libkse/thread/thr_create.c 113658 2003-04-18 05:04:16Z deischen $ | 33 * $FreeBSD: head/lib/libkse/thread/thr_create.c 113661 2003-04-18 07:09:43Z deischen $ |
33 */ 34#include <errno.h> 35#include <stdlib.h> 36#include <string.h> 37#include <fcntl.h> 38#include <unistd.h> 39#include <stddef.h> 40#include <sys/time.h> --- 61 unchanged lines hidden (view full) --- 102 if (_thr_initial == NULL) 103 _libpthread_init(NULL); 104 105 crit = _kse_critical_enter(); 106 curthread = _get_curthread(); 107 curkse = curthread->kse; 108 109 /* Allocate memory for the thread structure: */ | 34 */ 35#include <errno.h> 36#include <stdlib.h> 37#include <string.h> 38#include <fcntl.h> 39#include <unistd.h> 40#include <stddef.h> 41#include <sys/time.h> --- 61 unchanged lines hidden (view full) --- 103 if (_thr_initial == NULL) 104 _libpthread_init(NULL); 105 106 crit = _kse_critical_enter(); 107 curthread = _get_curthread(); 108 curkse = curthread->kse; 109 110 /* Allocate memory for the thread structure: */ |
110 if ((new_thread = _thr_alloc(curkse)) == NULL) { | 111 if ((new_thread = _thr_alloc(curthread)) == NULL) { |
111 /* Insufficient memory to create a thread: */ 112 ret = EAGAIN; 113 } else { 114 /* Initialize the thread structure: */ 115 memset(new_thread, 0, sizeof(struct pthread)); 116 117 /* Check if default thread attributes are required: */ 118 if (attr == NULL || *attr == NULL) 119 /* Use the default thread attributes: */ 120 new_thread->attr = _pthread_attr_default; 121 else 122 new_thread->attr = *(*attr); 123 124 if (create_stack(&new_thread->attr) != 0) { 125 /* Insufficient memory to create a stack: */ 126 ret = EAGAIN; | 112 /* Insufficient memory to create a thread: */ 113 ret = EAGAIN; 114 } else { 115 /* Initialize the thread structure: */ 116 memset(new_thread, 0, sizeof(struct pthread)); 117 118 /* Check if default thread attributes are required: */ 119 if (attr == NULL || *attr == NULL) 120 /* Use the default thread attributes: */ 121 new_thread->attr = _pthread_attr_default; 122 else 123 new_thread->attr = *(*attr); 124 125 if (create_stack(&new_thread->attr) != 0) { 126 /* Insufficient memory to create a stack: */ 127 ret = EAGAIN; |
127 _thr_free(curkse, new_thread); | 128 _thr_free(curthread, new_thread); |
128 } 129 else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) && | 129 } 130 else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) && |
130 (((kse = _kse_alloc(curkse)) == NULL) 131 || ((kseg = _kseg_alloc(curkse)) == NULL))) { | 131 (((kse = _kse_alloc(curthread)) == NULL) 132 || ((kseg = _kseg_alloc(curthread)) == NULL))) { |
132 /* Insufficient memory to create a new KSE/KSEG: */ 133 ret = EAGAIN; 134 if (kse != NULL) | 133 /* Insufficient memory to create a new KSE/KSEG: */ 134 ret = EAGAIN; 135 if (kse != NULL) |
135 _kse_free(curkse, kse); | 136 _kse_free(curthread, kse); |
136 if ((new_thread->attr.flags & THR_STACK_USER) == 0) { 137 KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); 138 _thr_stack_free(&new_thread->attr); 139 KSE_LOCK_RELEASE(curkse, &_thread_list_lock); 140 } | 137 if ((new_thread->attr.flags & THR_STACK_USER) == 0) { 138 KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); 139 _thr_stack_free(&new_thread->attr); 140 KSE_LOCK_RELEASE(curkse, &_thread_list_lock); 141 } |
141 _thr_free(curkse, new_thread); | 142 _thr_free(curthread, new_thread); |
142 } 143 else { 144 if (kseg != NULL) { 145 /* Add the KSE to the KSEG's list of KSEs. */ 146 TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_qe); 147 kse->k_kseg = kseg; 148 kse->k_schedq = &kseg->kg_schedq; 149 } --- 162 unchanged lines hidden --- | 143 } 144 else { 145 if (kseg != NULL) { 146 /* Add the KSE to the KSEG's list of KSEs. */ 147 TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_qe); 148 kse->k_kseg = kseg; 149 kse->k_schedq = &kseg->kg_schedq; 150 } --- 162 unchanged lines hidden --- |