Rev 814 | Rev 842 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 814 | Rev 822 | ||
|---|---|---|---|
| Line 224... | Line 224... | ||
| 224 | * |
224 | * |
| 225 | */ |
225 | */ |
| 226 | thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags) |
226 | thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags) |
| 227 | { |
227 | { |
| 228 | thread_t *t; |
228 | thread_t *t; |
| - | 229 | ipl_t ipl; |
|
| 229 | 230 | ||
| 230 | t = (thread_t *) slab_alloc(thread_slab, 0); |
231 | t = (thread_t *) slab_alloc(thread_slab, 0); |
| 231 | if (t) { |
- | |
| 232 | ipl_t ipl; |
- | |
| 233 | 232 | ||
| 234 | /* Not needed, but good for debugging */ |
233 | /* Not needed, but good for debugging */ |
| 235 | memsetb((__address)t->kstack, THREAD_STACK_SIZE, 0); |
234 | memsetb((__address)t->kstack, THREAD_STACK_SIZE, 0); |
| 236 | 235 | ||
| 237 | ipl = interrupts_disable(); |
236 | ipl = interrupts_disable(); |
| 238 | spinlock_lock(&tidlock); |
237 | spinlock_lock(&tidlock); |
| 239 | t->tid = ++last_tid; |
238 | t->tid = ++last_tid; |
| 240 | spinlock_unlock(&tidlock); |
239 | spinlock_unlock(&tidlock); |
| 241 | interrupts_restore(ipl); |
240 | interrupts_restore(ipl); |
| 242 | 241 | ||
| 243 | context_save(&t->saved_context); |
242 | context_save(&t->saved_context); |
| 244 | context_set(&t->saved_context, FADDR(cushion), (__address) t->kstack, THREAD_STACK_SIZE); |
243 | context_set(&t->saved_context, FADDR(cushion), (__address) t->kstack, THREAD_STACK_SIZE); |
| 245 | 244 | ||
| 246 | the_initialize((the_t *) t->kstack); |
245 | the_initialize((the_t *) t->kstack); |
| 247 | 246 | ||
| 248 | ipl = interrupts_disable(); |
247 | ipl = interrupts_disable(); |
| 249 | t->saved_context.ipl = interrupts_read(); |
248 | t->saved_context.ipl = interrupts_read(); |
| 250 | interrupts_restore(ipl); |
249 | interrupts_restore(ipl); |
| 251 | 250 | ||
| 252 | t->thread_code = func; |
251 | t->thread_code = func; |
| 253 | t->thread_arg = arg; |
252 | t->thread_arg = arg; |
| 254 | t->ticks = -1; |
253 | t->ticks = -1; |
| 255 | t->priority = -1; /* start in rq[0] */ |
254 | t->priority = -1; /* start in rq[0] */ |
| 256 | t->cpu = NULL; |
255 | t->cpu = NULL; |
| 257 | t->flags = 0; |
256 | t->flags = 0; |
| 258 | t->state = Entering; |
257 | t->state = Entering; |
| 259 | t->call_me = NULL; |
258 | t->call_me = NULL; |
| 260 | t->call_me_with = NULL; |
259 | t->call_me_with = NULL; |
| 261 | 260 | ||
| 262 | timeout_initialize(&t->sleep_timeout); |
261 | timeout_initialize(&t->sleep_timeout); |
| 263 | t->sleep_queue = NULL; |
262 | t->sleep_queue = NULL; |
| 264 | t->timeout_pending = 0; |
263 | t->timeout_pending = 0; |
| 265 | 264 | ||
| 266 | t->rwlock_holder_type = RWLOCK_NONE; |
265 | t->rwlock_holder_type = RWLOCK_NONE; |
| 267 | - | ||
| 268 | t->task = task; |
- | |
| 269 | - | ||
| 270 | t->fpu_context_exists=0; |
- | |
| 271 | t->fpu_context_engaged=0; |
- | |
| 272 | 266 | ||
| - | 267 | t->task = task; |
|
| - | 268 | ||
| - | 269 | t->fpu_context_exists=0; |
|
| - | 270 | t->fpu_context_engaged=0; |
|
| - | 271 | ||
| 273 | /* |
272 | /* |
| 274 | * Register this thread in the system-wide list. |
273 | * Register this thread in the system-wide list. |
| 275 | */ |
274 | */ |
| 276 | ipl = interrupts_disable(); |
275 | ipl = interrupts_disable(); |
| 277 | spinlock_lock(&threads_lock); |
276 | spinlock_lock(&threads_lock); |
| 278 | list_append(&t->threads_link, &threads_head); |
277 | list_append(&t->threads_link, &threads_head); |
| 279 | spinlock_unlock(&threads_lock); |
278 | spinlock_unlock(&threads_lock); |
| 280 | 279 | ||
| 281 | /* |
280 | /* |
| 282 | * Attach to the containing task. |
281 | * Attach to the containing task. |
| 283 | */ |
282 | */ |
| 284 | spinlock_lock(&task->lock); |
283 | spinlock_lock(&task->lock); |
| 285 | list_append(&t->th_link, &task->th_head); |
284 | list_append(&t->th_link, &task->th_head); |
| 286 | spinlock_unlock(&task->lock); |
285 | spinlock_unlock(&task->lock); |
| 287 | 286 | ||
| 288 | interrupts_restore(ipl); |
287 | interrupts_restore(ipl); |
| 289 | } |
- | |
| 290 | 288 | ||
| 291 | return t; |
289 | return t; |
| 292 | } |
290 | } |
| 293 | 291 | ||
| 294 | 292 | ||