Changeset b91bb65 in mainline
- Timestamp:
- 2006-06-05T14:11:18Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c1c677
- Parents:
- e090e1bc
- Location:
- generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/proc/task.h
re090e1bc rb91bb65 49 49 50 50 char *name; 51 thread_t *main_thread; /**< Pointer to the main thread. */ 51 52 link_t th_head; /**< List of threads contained in this task. */ 52 53 as_t *as; /**< Address space. */ -
generic/src/proc/task.c
re090e1bc rb91bb65 59 59 static task_id_t task_counter = 0; 60 60 61 static void ktaskclnp(void *); 61 static void ktaskclnp(void *arg); 62 static void ktaskkill(void *arg); 62 63 63 64 /** Initialize tasks … … 97 98 ta->as = as; 98 99 ta->name = name; 99 100 ta->main_thread = NULL; 100 101 ta->refcount = 0; 101 102 … … 154 155 as_area_t *a; 155 156 int rc; 156 thread_t *t ;157 thread_t *t1, *t2; 157 158 task_t *task; 158 159 uspace_arg_t *kernel_uarg; … … 184 185 USTACK_ADDRESS, AS_AREA_ATTR_NONE, &anon_backend, NULL); 185 186 186 t = thread_create(uinit, kernel_uarg, task, 0, "uinit"); 187 ASSERT(t); 188 thread_ready(t); 189 187 /* 188 * Create the main thread. 189 */ 190 t1 = thread_create(uinit, kernel_uarg, task, 0, "uinit"); 191 ASSERT(t1); 192 193 /* 194 * Create killer thread for the new task. 195 */ 196 t2 = thread_create(ktaskkill, t1, task, 0, "ktaskkill"); 197 ASSERT(t2); 198 thread_ready(t2); 199 200 thread_ready(t1); 201 190 202 return task; 191 203 } … … 253 265 ta->accept_new_threads = false; 254 266 ta->refcount--; 255 267 268 /* 269 * Interrupt all threads except this one. 270 */ 256 271 for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { 257 272 thread_t *thr; … … 318 333 } 319 334 320 /** Kernel thread used to cleanup the task . */335 /** Kernel thread used to cleanup the task after it is killed. */ 321 336 void ktaskclnp(void *arg) 322 337 { 323 338 ipl_t ipl; 324 thread_t *t = NULL ;339 thread_t *t = NULL, *main_thread; 325 340 link_t *cur; 326 341 … … 330 345 ipl = interrupts_disable(); 331 346 spinlock_lock(&TASK->lock); 347 348 main_thread = TASK->main_thread; 332 349 333 350 /* … … 338 355 if (t == THREAD) 339 356 continue; 357 else if (t == main_thread) 358 continue; 340 359 else 341 360 break; … … 346 365 347 366 if (t != THREAD) { 367 ASSERT(t != main_thread); /* uninit is joined and detached in ktaskkill */ 348 368 thread_join(t); 349 369 thread_detach(t); 350 goto loop; 370 goto loop; /* go for another thread */ 351 371 } 352 372 … … 359 379 futex_cleanup(); 360 380 } 381 382 /** Kernel task used to kill a userspace task when its main thread exits. 383 * 384 * This thread waits until the main userspace thread (i.e. uninit) exits. 385 * When this happens, the task is killed. 386 * 387 * @param arg Pointer to the thread structure of the task's main thread. 388 */ 389 void ktaskkill(void *arg) 390 { 391 thread_t *t = (thread_t *) arg; 392 393 /* 394 * Userspace threads cannot detach themselves, 395 * therefore the thread pointer is guaranteed to be valid. 396 */ 397 thread_join(t); /* sleep uninterruptibly here! */ 398 thread_detach(t); 399 task_kill(TASK->taskid); 400 } -
generic/src/proc/thread.c
re090e1bc rb91bb65 351 351 } 352 352 list_append(&t->th_link, &task->th_head); 353 task->refcount++; 353 if (task->refcount++ == 0) 354 task->main_thread = t; 354 355 spinlock_unlock(&task->lock); 355 356
Note:
See TracChangeset
for help on using the changeset viewer.