thr_create.c (212076) | thr_create.c (212536) |
---|---|
1/* 2 * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com> 3 * Copyright (c) 2005, David Xu <davidxu@freebsd.org> 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: --- 10 unchanged lines hidden (view full) --- 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * | 1/* 2 * Copyright (c) 2003 Daniel M. Eischen <deischen@gdeb.com> 3 * Copyright (c) 2005, David Xu <davidxu@freebsd.org> 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: --- 10 unchanged lines hidden (view full) --- 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/lib/libthr/thread/thr_create.c 212076 2010-09-01 02:18:33Z davidxu $ | 27 * $FreeBSD: head/lib/libthr/thread/thr_create.c 212536 2010-09-13 07:03:01Z davidxu $ |
28 */ 29 30#include "namespace.h" 31#include <sys/types.h> 32#include <sys/rtprio.h> 33#include <sys/signalvar.h> 34#include <errno.h> 35#include <stdlib.h> --- 84 unchanged lines hidden (view full) --- 120 create_suspended = 1; 121 } else { 122 create_suspended = 0; 123 } 124 125 new_thread->state = PS_RUNNING; 126 127 if (new_thread->attr.flags & PTHREAD_CREATE_DETACHED) | 28 */ 29 30#include "namespace.h" 31#include <sys/types.h> 32#include <sys/rtprio.h> 33#include <sys/signalvar.h> 34#include <errno.h> 35#include <stdlib.h> --- 84 unchanged lines hidden (view full) --- 120 create_suspended = 1; 121 } else { 122 create_suspended = 0; 123 } 124 125 new_thread->state = PS_RUNNING; 126 127 if (new_thread->attr.flags & PTHREAD_CREATE_DETACHED) |
128 new_thread->tlflags |= TLFLAGS_DETACHED; | 128 new_thread->flags |= THR_FLAGS_DETACHED; |
129 130 /* Add the new thread. */ 131 new_thread->refcount = 1; 132 _thr_link(curthread, new_thread); 133 /* Return thread pointer eariler so that new thread can use it. */ 134 (*thread) = new_thread; 135 if (SHOULD_REPORT_EVENT(curthread, TD_CREATE) || cpusetp != NULL) { 136 THR_THREAD_LOCK(curthread, new_thread); --- 43 unchanged lines hidden (view full) --- 180 if (create_suspended) 181 __sys_sigprocmask(SIG_SETMASK, &oset, NULL); 182 183 if (ret != 0) { 184 if (!locked) 185 THR_THREAD_LOCK(curthread, new_thread); 186 new_thread->state = PS_DEAD; 187 new_thread->tid = TID_TERMINATED; | 129 130 /* Add the new thread. */ 131 new_thread->refcount = 1; 132 _thr_link(curthread, new_thread); 133 /* Return thread pointer eariler so that new thread can use it. */ 134 (*thread) = new_thread; 135 if (SHOULD_REPORT_EVENT(curthread, TD_CREATE) || cpusetp != NULL) { 136 THR_THREAD_LOCK(curthread, new_thread); --- 43 unchanged lines hidden (view full) --- 180 if (create_suspended) 181 __sys_sigprocmask(SIG_SETMASK, &oset, NULL); 182 183 if (ret != 0) { 184 if (!locked) 185 THR_THREAD_LOCK(curthread, new_thread); 186 new_thread->state = PS_DEAD; 187 new_thread->tid = TID_TERMINATED; |
188 new_thread->flags |= THR_FLAGS_DETACHED; 189 new_thread->refcount--; |
|
188 if (new_thread->flags & THR_FLAGS_NEED_SUSPEND) { 189 new_thread->cycle++; 190 _thr_umtx_wake(&new_thread->cycle, INT_MAX, 0); 191 } | 190 if (new_thread->flags & THR_FLAGS_NEED_SUSPEND) { 191 new_thread->cycle++; 192 _thr_umtx_wake(&new_thread->cycle, INT_MAX, 0); 193 } |
192 THR_THREAD_UNLOCK(curthread, new_thread); 193 THREAD_LIST_LOCK(curthread); 194 _thread_active_threads--; 195 new_thread->tlflags |= TLFLAGS_DETACHED; 196 _thr_ref_delete_unlocked(curthread, new_thread); 197 THREAD_LIST_UNLOCK(curthread); | 194 _thr_try_gc(curthread, new_thread); /* thread lock released */ 195 atomic_add_int(&_thread_active_threads, -1); |
198 } else if (locked) { 199 if (cpusetp != NULL) { 200 if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, 201 TID(new_thread), cpusetsize, cpusetp)) { 202 ret = errno; 203 /* kill the new thread */ 204 new_thread->force_exit = 1; | 196 } else if (locked) { 197 if (cpusetp != NULL) { 198 if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, 199 TID(new_thread), cpusetsize, cpusetp)) { 200 ret = errno; 201 /* kill the new thread */ 202 new_thread->force_exit = 1; |
205 THR_THREAD_UNLOCK(curthread, new_thread); | 203 new_thread->flags |= THR_FLAGS_DETACHED; 204 _thr_try_gc(curthread, new_thread); 205 /* thread lock released */ |
206 goto out; 207 } 208 } 209 210 _thr_report_creation(curthread, new_thread); 211 THR_THREAD_UNLOCK(curthread, new_thread); | 206 goto out; 207 } 208 } 209 210 _thr_report_creation(curthread, new_thread); 211 THR_THREAD_UNLOCK(curthread, new_thread); |
212out: 213 if (ret) { 214 THREAD_LIST_LOCK(curthread); 215 new_thread->tlflags |= TLFLAGS_DETACHED; 216 THR_GCLIST_ADD(new_thread); 217 THREAD_LIST_UNLOCK(curthread); 218 } | |
219 } | 212 } |
220 | 213out: |
221 if (ret) 222 (*thread) = 0; 223 return (ret); 224} 225 226static int 227create_stack(struct pthread_attr *pattr) 228{ --- 51 unchanged lines hidden --- | 214 if (ret) 215 (*thread) = 0; 216 return (ret); 217} 218 219static int 220create_stack(struct pthread_attr *pattr) 221{ --- 51 unchanged lines hidden --- |