thr_create.c (118514) | thr_create.c (120074) |
---|---|
1/* 2 * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com> 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: --- 16 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 * | 1/* 2 * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com> 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: --- 16 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 * |
33 * $FreeBSD: head/lib/libkse/thread/thr_create.c 118514 2003-08-06 00:23:40Z marcel $ | 33 * $FreeBSD: head/lib/libkse/thread/thr_create.c 120074 2003-09-14 22:52:16Z davidxu $ |
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> --- 52 unchanged lines hidden (view full) --- 94int 95_pthread_create(pthread_t * thread, const pthread_attr_t * attr, 96 void *(*start_routine) (void *), void *arg) 97{ 98 struct pthread *curthread, *new_thread; 99 struct kse *kse = NULL; 100 struct kse_group *kseg = NULL; 101 kse_critical_t crit; | 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> --- 52 unchanged lines hidden (view full) --- 94int 95_pthread_create(pthread_t * thread, const pthread_attr_t * attr, 96 void *(*start_routine) (void *), void *arg) 97{ 98 struct pthread *curthread, *new_thread; 99 struct kse *kse = NULL; 100 struct kse_group *kseg = NULL; 101 kse_critical_t crit; |
102 int i; | |
103 int ret = 0; 104 105 if (_thr_initial == NULL) 106 _libpthread_init(NULL); 107 108 /* 109 * Turn on threaded mode, if failed, it is unnecessary to 110 * do further work. --- 11 unchanged lines hidden (view full) --- 122 if ((new_thread = _thr_alloc(curthread)) == NULL) { 123 /* Insufficient memory to create a thread: */ 124 ret = EAGAIN; 125 } else { 126 /* Check if default thread attributes are required: */ 127 if (attr == NULL || *attr == NULL) 128 /* Use the default thread attributes: */ 129 new_thread->attr = _pthread_attr_default; | 102 int ret = 0; 103 104 if (_thr_initial == NULL) 105 _libpthread_init(NULL); 106 107 /* 108 * Turn on threaded mode, if failed, it is unnecessary to 109 * do further work. --- 11 unchanged lines hidden (view full) --- 121 if ((new_thread = _thr_alloc(curthread)) == NULL) { 122 /* Insufficient memory to create a thread: */ 123 ret = EAGAIN; 124 } else { 125 /* Check if default thread attributes are required: */ 126 if (attr == NULL || *attr == NULL) 127 /* Use the default thread attributes: */ 128 new_thread->attr = _pthread_attr_default; |
130 else | 129 else { |
131 new_thread->attr = *(*attr); | 130 new_thread->attr = *(*attr); |
131 if ((*attr)->sched_inherit == PTHREAD_INHERIT_SCHED) { 132 /* inherit scheduling contention scop */ 133 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) 134 new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM; 135 else 136 new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM; 137 /* 138 * scheduling policy and scheduling parameters will be 139 * inherited in following code. 140 */ 141 } 142 } |
|
132#ifdef SYSTEM_SCOPE_ONLY 133 new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM; 134#endif 135 if (create_stack(&new_thread->attr) != 0) { 136 /* Insufficient memory to create a stack: */ 137 ret = EAGAIN; 138 _thr_free(curthread, new_thread); 139 } --- 54 unchanged lines hidden (view full) --- 194 new_thread->attr.stackaddr_attr; 195 makecontext(&new_thread->tcb->tcb_tmbx.tm_context, 196 (void (*)(void))thread_start, 3, new_thread, 197 start_routine, arg); 198 /* 199 * Check if this thread is to inherit the scheduling 200 * attributes from its parent: 201 */ | 143#ifdef SYSTEM_SCOPE_ONLY 144 new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM; 145#endif 146 if (create_stack(&new_thread->attr) != 0) { 147 /* Insufficient memory to create a stack: */ 148 ret = EAGAIN; 149 _thr_free(curthread, new_thread); 150 } --- 54 unchanged lines hidden (view full) --- 205 new_thread->attr.stackaddr_attr; 206 makecontext(&new_thread->tcb->tcb_tmbx.tm_context, 207 (void (*)(void))thread_start, 3, new_thread, 208 start_routine, arg); 209 /* 210 * Check if this thread is to inherit the scheduling 211 * attributes from its parent: 212 */ |
202 if ((new_thread->attr.flags & PTHREAD_INHERIT_SCHED) != 0) { | 213 if (new_thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED) { |
203 /* 204 * Copy the scheduling attributes. 205 * Lock the scheduling lock to get consistent 206 * scheduling parameters. 207 */ 208 THR_SCHED_LOCK(curthread, curthread); 209 new_thread->base_priority = 210 curthread->base_priority & --- 14 unchanged lines hidden (view full) --- 225 new_thread->attr.prio; 226 } 227 new_thread->active_priority = new_thread->base_priority; 228 new_thread->inherited_priority = 0; 229 230 /* Initialize the mutex queue: */ 231 TAILQ_INIT(&new_thread->mutexq); 232 | 214 /* 215 * Copy the scheduling attributes. 216 * Lock the scheduling lock to get consistent 217 * scheduling parameters. 218 */ 219 THR_SCHED_LOCK(curthread, curthread); 220 new_thread->base_priority = 221 curthread->base_priority & --- 14 unchanged lines hidden (view full) --- 236 new_thread->attr.prio; 237 } 238 new_thread->active_priority = new_thread->base_priority; 239 new_thread->inherited_priority = 0; 240 241 /* Initialize the mutex queue: */ 242 TAILQ_INIT(&new_thread->mutexq); 243 |
233 /* 234 * Initialize thread locking. 235 * Lock initializing needs malloc, so don't 236 * enter critical region before doing this! 237 */ 238 if (_lock_init(&new_thread->lock, LCK_ADAPTIVE, 239 _thr_lock_wait, _thr_lock_wakeup) != 0) 240 PANIC("Cannot initialize thread lock"); 241 for (i = 0; i < MAX_THR_LOCKLEVEL; i++) { 242 _lockuser_init(&new_thread->lockusers[i], 243 (void *)new_thread); 244 _LCK_SET_PRIVATE2(&new_thread->lockusers[i], 245 (void *)new_thread); 246 } 247 | |
248 /* Initialise hooks in the thread structure: */ 249 new_thread->specific = NULL; | 244 /* Initialise hooks in the thread structure: */ 245 new_thread->specific = NULL; |
246 new_thread->specific_data_count = 0; |
|
250 new_thread->cleanup = NULL; 251 new_thread->flags = 0; 252 new_thread->continuation = NULL; | 247 new_thread->cleanup = NULL; 248 new_thread->flags = 0; 249 new_thread->continuation = NULL; |
250 new_thread->wakeup_time.tv_sec = -1; 251 new_thread->lock_switch = 0; 252 sigemptyset(&new_thread->sigpend); 253 new_thread->check_pending = 0; 254 new_thread->locklevel = 0; |
|
253 254 if (new_thread->attr.suspend == THR_CREATE_SUSPENDED) { 255 new_thread->state = PS_SUSPENDED; 256 new_thread->flags = THR_FLAGS_SUSPENDED; 257 } 258 else 259 new_thread->state = PS_RUNNING; 260 --- 91 unchanged lines hidden --- | 255 256 if (new_thread->attr.suspend == THR_CREATE_SUSPENDED) { 257 new_thread->state = PS_SUSPENDED; 258 new_thread->flags = THR_FLAGS_SUSPENDED; 259 } 260 else 261 new_thread->state = PS_RUNNING; 262 --- 91 unchanged lines hidden --- |