Deleted Added
full compact
thr_create.c (114664) thr_create.c (115278)
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 114664 2003-05-04 16:17:01Z deischen $
33 * $FreeBSD: head/lib/libkse/thread/thr_create.c 115278 2003-05-24 02:29:25Z deischen $
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>
42#include <machine/reg.h>
43#include <pthread.h>
44#include "thr_private.h"
45#include "libc_private.h"
46
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>
42#include <machine/reg.h>
43#include <pthread.h>
44#include "thr_private.h"
45#include "libc_private.h"
46
47static u_int64_t next_uniqueid = 1;
48
49#define OFF(f) offsetof(struct pthread, f)
50int _thread_next_offset = OFF(tle.tqe_next);
51int _thread_uniqueid_offset = OFF(uniqueid);
52int _thread_state_offset = OFF(state);
53int _thread_name_offset = OFF(name);
54int _thread_ctx_offset = OFF(tmbx.tm_context);
55#undef OFF
56

--- 83 unchanged lines hidden (view full) ---

140 ret = EAGAIN;
141 _thr_free(curthread, new_thread);
142 }
143 else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) &&
144 (((kse = _kse_alloc(curthread)) == NULL)
145 || ((kseg = _kseg_alloc(curthread)) == NULL))) {
146 /* Insufficient memory to create a new KSE/KSEG: */
147 ret = EAGAIN;
47#define OFF(f) offsetof(struct pthread, f)
48int _thread_next_offset = OFF(tle.tqe_next);
49int _thread_uniqueid_offset = OFF(uniqueid);
50int _thread_state_offset = OFF(state);
51int _thread_name_offset = OFF(name);
52int _thread_ctx_offset = OFF(tmbx.tm_context);
53#undef OFF
54

--- 83 unchanged lines hidden (view full) ---

138 ret = EAGAIN;
139 _thr_free(curthread, new_thread);
140 }
141 else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) &&
142 (((kse = _kse_alloc(curthread)) == NULL)
143 || ((kseg = _kseg_alloc(curthread)) == NULL))) {
144 /* Insufficient memory to create a new KSE/KSEG: */
145 ret = EAGAIN;
148 if (kse != NULL)
146#ifndef KMF_DONE
147#define KMF_DONE 0x04
148#endif
149 if (kse != NULL) {
150 kse->k_mbx.km_flags |= KMF_DONE;
149 _kse_free(curthread, kse);
151 _kse_free(curthread, kse);
152 }
150 if ((new_thread->attr.flags & THR_STACK_USER) == 0) {
151 crit = _kse_critical_enter();
152 curkse = _get_curkse();
153 KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
154 /* Stack routines don't use malloc/free. */
155 _thr_stack_free(&new_thread->attr);
156 KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
157 _kse_critical_leave(crit);
158 }
159 _thr_free(curthread, new_thread);
160 }
161 else {
162 if (kseg != NULL) {
163 /* Add the KSE to the KSEG's list of KSEs. */
153 if ((new_thread->attr.flags & THR_STACK_USER) == 0) {
154 crit = _kse_critical_enter();
155 curkse = _get_curkse();
156 KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
157 /* Stack routines don't use malloc/free. */
158 _thr_stack_free(&new_thread->attr);
159 KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
160 _kse_critical_leave(crit);
161 }
162 _thr_free(curthread, new_thread);
163 }
164 else {
165 if (kseg != NULL) {
166 /* Add the KSE to the KSEG's list of KSEs. */
164 TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_qe);
167 TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_kgqe);
168 kseg->kg_ksecount = 1;
165 kse->k_kseg = kseg;
166 kse->k_schedq = &kseg->kg_schedq;
167 }
168 /*
169 * Write a magic value to the thread structure
170 * to help identify valid ones:
171 */
172 new_thread->magic = THR_MAGIC;

--- 108 unchanged lines hidden (view full) ---

281 kse->k_kseg->kg_flags |= KGF_SINGLE_THREAD;
282#endif
283 new_thread->kse = kse;
284 new_thread->kseg = kse->k_kseg;
285 kse->k_mbx.km_udata = kse;
286 kse->k_mbx.km_curthread = NULL;
287 }
288
169 kse->k_kseg = kseg;
170 kse->k_schedq = &kseg->kg_schedq;
171 }
172 /*
173 * Write a magic value to the thread structure
174 * to help identify valid ones:
175 */
176 new_thread->magic = THR_MAGIC;

--- 108 unchanged lines hidden (view full) ---

285 kse->k_kseg->kg_flags |= KGF_SINGLE_THREAD;
286#endif
287 new_thread->kse = kse;
288 new_thread->kseg = kse->k_kseg;
289 kse->k_mbx.km_udata = kse;
290 kse->k_mbx.km_curthread = NULL;
291 }
292
289 crit = _kse_critical_enter();
290 KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
291 /*
293 /*
292 * Initialise the unique id which GDB uses to
293 * track threads.
294 */
295 new_thread->uniqueid = next_uniqueid++;
296 /* Add the thread to the linked list of all threads: */
297 THR_LIST_ADD(new_thread);
298 KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
299
300 /*
301 * Schedule the new thread starting a new KSEG/KSE
302 * pair if necessary.
303 */
304 ret = _thr_schedule_add(curthread, new_thread);
294 * Schedule the new thread starting a new KSEG/KSE
295 * pair if necessary.
296 */
297 ret = _thr_schedule_add(curthread, new_thread);
305 if (ret != 0) {
306 KSE_LOCK_ACQUIRE(curthread->kse,
307 &_thread_list_lock);
308 THR_LIST_REMOVE(new_thread);
309 KSE_LOCK_RELEASE(curthread->kse,
310 &_thread_list_lock);
311 }
312 _kse_critical_leave(crit);
313 if (ret != 0)
314 free_thread(curthread, new_thread);
315
316 /* Return a pointer to the thread structure: */
317 (*thread) = new_thread;
318 }
319 }
320

--- 15 unchanged lines hidden (view full) ---

336static int
337create_stack(struct pthread_attr *pattr)
338{
339 int ret;
340
341 /* Check if a stack was specified in the thread attributes: */
342 if ((pattr->stackaddr_attr) != NULL) {
343 pattr->guardsize_attr = 0;
298 if (ret != 0)
299 free_thread(curthread, new_thread);
300
301 /* Return a pointer to the thread structure: */
302 (*thread) = new_thread;
303 }
304 }
305

--- 15 unchanged lines hidden (view full) ---

321static int
322create_stack(struct pthread_attr *pattr)
323{
324 int ret;
325
326 /* Check if a stack was specified in the thread attributes: */
327 if ((pattr->stackaddr_attr) != NULL) {
328 pattr->guardsize_attr = 0;
344 pattr->flags = THR_STACK_USER;
329 pattr->flags |= THR_STACK_USER;
345 ret = 0;
346 }
347 else
348 ret = _thr_stack_alloc(pattr);
349 return (ret);
350}
351
352
353static void
354thread_start(struct pthread *curthread, void *(*start_routine) (void *),
355 void *arg)
356{
357 /* Run the current thread's start routine with argument: */
358 pthread_exit(start_routine(arg));
359
360 /* This point should never be reached. */
361 PANIC("Thread has resumed after exit");
362}
330 ret = 0;
331 }
332 else
333 ret = _thr_stack_alloc(pattr);
334 return (ret);
335}
336
337
338static void
339thread_start(struct pthread *curthread, void *(*start_routine) (void *),
340 void *arg)
341{
342 /* Run the current thread's start routine with argument: */
343 pthread_exit(start_routine(arg));
344
345 /* This point should never be reached. */
346 PANIC("Thread has resumed after exit");
347}