sched: implement various ways to end tasks and threads
This commit is contained in:
@@ -65,9 +65,6 @@ kern_status_t thread_init_user(
|
||||
const uintptr_t *args,
|
||||
size_t nr_args)
|
||||
{
|
||||
thr->tr_id = thr->tr_parent->t_next_thread_id++;
|
||||
|
||||
thr->tr_prio = PRIO_NORMAL;
|
||||
thr->tr_state = THREAD_READY;
|
||||
thr->tr_quantum_target = default_quantum();
|
||||
|
||||
@@ -144,6 +141,55 @@ void thread_awaken(struct thread *thr)
|
||||
rq_unlock(rq, flags);
|
||||
}
|
||||
|
||||
void thread_exit(void)
|
||||
{
|
||||
struct thread *self = current_thread();
|
||||
unsigned long flags;
|
||||
thread_lock_irqsave(self, &flags);
|
||||
self->tr_state = THREAD_STOPPED;
|
||||
object_assert_signal(&self->tr_base, THREAD_SIGNAL_STOPPED);
|
||||
printk("thread %s[%u.%u] exited",
|
||||
self->tr_parent->t_name,
|
||||
self->tr_parent->t_id,
|
||||
self->tr_id);
|
||||
thread_unlock_irqrestore(self, flags);
|
||||
|
||||
while (1) {
|
||||
schedule(SCHED_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_join(struct thread *thread, unsigned long *irq_flags)
|
||||
{
|
||||
while (1) {
|
||||
if (thread->tr_state == THREAD_STOPPED) {
|
||||
break;
|
||||
}
|
||||
|
||||
object_wait_signal(
|
||||
&thread->tr_base,
|
||||
THREAD_SIGNAL_STOPPED,
|
||||
irq_flags);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_kill(struct thread *thread)
|
||||
{
|
||||
thread->tr_state = THREAD_STOPPED;
|
||||
if (thread->tr_rq) {
|
||||
unsigned long flags;
|
||||
rq_lock(thread->tr_rq, &flags);
|
||||
rq_remove_thread(thread->tr_rq, thread);
|
||||
rq_unlock(thread->tr_rq, flags);
|
||||
}
|
||||
|
||||
object_assert_signal(&thread->tr_base, THREAD_SIGNAL_STOPPED);
|
||||
printk("thread %s[%u.%u] killed",
|
||||
thread->tr_parent->t_name,
|
||||
thread->tr_parent->t_id,
|
||||
thread->tr_id);
|
||||
}
|
||||
|
||||
struct thread *create_kernel_thread(void (*fn)(void))
|
||||
{
|
||||
struct task *kernel = kernel_task();
|
||||
|
||||
Reference in New Issue
Block a user