58,8 → 58,7 |
btree_t tasks_btree; |
static task_id_t task_counter = 0; |
|
static void ktaskclnp(void *arg); |
static void ktaskkill(void *arg); |
static void ktaskclnp(void *); |
|
/** Initialize tasks |
* |
97,7 → 96,7 |
list_initialize(&ta->th_head); |
ta->as = as; |
ta->name = name; |
ta->main_thread = NULL; |
|
ta->refcount = 0; |
|
ta->capabilities = 0; |
154,7 → 153,7 |
as_t *as; |
as_area_t *a; |
int rc; |
thread_t *t1, *t2; |
thread_t *t; |
task_t *task; |
uspace_arg_t *kernel_uarg; |
|
184,21 → 183,10 |
LOADED_PROG_STACK_PAGES_NO*PAGE_SIZE, |
USTACK_ADDRESS, AS_AREA_ATTR_NONE, &anon_backend, NULL); |
|
/* |
* Create the main thread. |
*/ |
t1 = thread_create(uinit, kernel_uarg, task, 0, "uinit"); |
ASSERT(t1); |
t = thread_create(uinit, kernel_uarg, task, 0, "uinit"); |
ASSERT(t); |
thread_ready(t); |
|
/* |
* Create killer thread for the new task. |
*/ |
t2 = thread_create(ktaskkill, t1, task, 0, "ktaskkill"); |
ASSERT(t2); |
thread_ready(t2); |
|
thread_ready(t1); |
|
return task; |
} |
|
264,10 → 252,7 |
spinlock_lock(&ta->lock); |
ta->accept_new_threads = false; |
ta->refcount--; |
|
/* |
* Interrupt all threads except this one. |
*/ |
|
for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
thread_t *thr; |
bool sleeping = false; |
332,11 → 317,11 |
interrupts_restore(ipl); |
} |
|
/** Kernel thread used to cleanup the task after it is killed. */ |
/** Kernel thread used to cleanup the task. */ |
void ktaskclnp(void *arg) |
{ |
ipl_t ipl; |
thread_t *t = NULL, *main_thread; |
thread_t *t = NULL; |
link_t *cur; |
|
thread_detach(THREAD); |
345,8 → 330,6 |
ipl = interrupts_disable(); |
spinlock_lock(&TASK->lock); |
|
main_thread = TASK->main_thread; |
|
/* |
* Find a thread to join. |
*/ |
354,8 → 337,6 |
t = list_get_instance(cur, thread_t, th_link); |
if (t == THREAD) |
continue; |
else if (t == main_thread) |
continue; |
else |
break; |
} |
364,10 → 345,9 |
interrupts_restore(ipl); |
|
if (t != THREAD) { |
ASSERT(t != main_thread); /* uninit is joined and detached in ktaskkill */ |
thread_join(t); |
thread_detach(t); |
goto loop; /* go for another thread */ |
goto loop; |
} |
|
/* |
378,23 → 358,3 |
ipc_cleanup(); |
futex_cleanup(); |
} |
|
/** Kernel task used to kill a userspace task when its main thread exits. |
* |
* This thread waits until the main userspace thread (i.e. uninit) exits. |
* When this happens, the task is killed. |
* |
* @param arg Pointer to the thread structure of the task's main thread. |
*/ |
void ktaskkill(void *arg) |
{ |
thread_t *t = (thread_t *) arg; |
|
/* |
* Userspace threads cannot detach themselves, |
* therefore the thread pointer is guaranteed to be valid. |
*/ |
thread_join(t); /* sleep uninterruptibly here! */ |
thread_detach(t); |
task_kill(TASK->taskid); |
} |