Deleted Added
sdiff udiff text old ( 113661 ) new ( 113786 )
full compact
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 113661 2003-04-18 07:09:43Z 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>

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

98 struct kse_group *kseg = NULL;
99 kse_critical_t crit;
100 int i;
101 int ret = 0;
102
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: */
111 if ((new_thread = _thr_alloc(curthread)) == NULL) {
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: */

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

130 else if (((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) &&
131 (((kse = _kse_alloc(curthread)) == NULL)
132 || ((kseg = _kseg_alloc(curthread)) == NULL))) {
133 /* Insufficient memory to create a new KSE/KSEG: */
134 ret = EAGAIN;
135 if (kse != NULL)
136 _kse_free(curthread, kse);
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 }
142 _thr_free(curthread, new_thread);
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;

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

164 new_thread->sigmask = curthread->sigmask;
165
166 /* No thread is wanting to join to this one: */
167 new_thread->joiner = NULL;
168
169 /* Initialize the signal frame: */
170 new_thread->curframe = NULL;
171
172 /* Initialize the machine context: */
173 THR_GETCONTEXT(&new_thread->tmbx.tm_context);
174 new_thread->tmbx.tm_udata = new_thread;
175 new_thread->tmbx.tm_context.uc_sigmask =
176 new_thread->sigmask;
177 new_thread->tmbx.tm_context.uc_stack.ss_size =
178 new_thread->attr.stacksize_attr;
179 new_thread->tmbx.tm_context.uc_stack.ss_sp =
180 new_thread->attr.stackaddr_attr;
181
182 makecontext(&new_thread->tmbx.tm_context,
183 (void (*)(void))thread_start, 4, new_thread,
184 start_routine, arg);
185
186 /*
187 * Check if this thread is to inherit the scheduling
188 * attributes from its parent:
189 */
190 if ((new_thread->attr.flags & PTHREAD_INHERIT_SCHED) != 0) {
191 /* Copy the scheduling attributes: */
192 new_thread->base_priority =
193 curthread->base_priority &
194 ~THR_SIGNAL_PRIORITY;
195 new_thread->attr.prio =
196 curthread->base_priority &
197 ~THR_SIGNAL_PRIORITY;
198 new_thread->attr.sched_policy =
199 curthread->attr.sched_policy;
200 } else {
201 /*
202 * Use just the thread priority, leaving the
203 * other scheduling attributes as their
204 * default values:
205 */
206 new_thread->base_priority =
207 new_thread->attr.prio;
208 }
209 new_thread->active_priority = new_thread->base_priority;
210 new_thread->inherited_priority = 0;
211
212 /* Initialize the mutex queue: */
213 TAILQ_INIT(&new_thread->mutexq);
214
215 /* Initialize thread locking. */
216 if (_lock_init(&new_thread->lock, LCK_ADAPTIVE,
217 _thr_lock_wait, _thr_lock_wakeup) != 0)
218 PANIC("Cannot initialize thread lock");
219 for (i = 0; i < MAX_THR_LOCKLEVEL; i++) {
220 _lockuser_init(&new_thread->lockusers[i],
221 (void *)new_thread);
222 _LCK_SET_PRIVATE2(&new_thread->lockusers[i],
223 (void *)new_thread);

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

240 * off the main process kseg.
241 */
242 if ((new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM) == 0) {
243 new_thread->kseg = _kse_initial->k_kseg;
244 new_thread->kse = _kse_initial;
245 }
246 else {
247 kse->k_curthread = NULL;
248 kse->k_kseg->kg_flags |= KGF_SINGLE_THREAD;
249 new_thread->kse = kse;
250 new_thread->kseg = kse->k_kseg;
251 kse->k_mbx.km_udata = kse;
252 kse->k_mbx.km_curthread = NULL;
253 }
254 KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
255
256 /*
257 * Initialise the unique id which GDB uses to
258 * track threads.
259 */
260 new_thread->uniqueid = next_uniqueid++;
261
262 /* Add the thread to the linked list of all threads: */
263 THR_LIST_ADD(new_thread);
264
265 KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
266
267 /*
268 * Schedule the new thread starting a new KSEG/KSE
269 * pair if necessary.
270 */
271 _thr_schedule_add(curthread, new_thread);
272
273 /* Return a pointer to the thread structure: */
274 (*thread) = new_thread;
275 }
276 }
277 _kse_critical_leave(crit);
278
279 if ((ret == 0) && (_kse_isthreaded() == 0))
280 _kse_setthreaded(1);
281
282 /* Return the status: */
283 return (ret);
284}
285
286static int
287create_stack(struct pthread_attr *pattr)
288{
289 int ret;

--- 23 unchanged lines hidden ---