add: zombify task
This commit is contained in:
parent
a9ed5947a8
commit
3766464c47
@ -36,6 +36,7 @@ i8 create_kernel_task(void);
|
|||||||
void remove_task(struct task *task);
|
void remove_task(struct task *task);
|
||||||
struct task *copy_task(const struct task *task);
|
struct task *copy_task(const struct task *task);
|
||||||
void kfork(struct task *daddy);
|
void kfork(struct task *daddy);
|
||||||
|
void zombify_task(struct task *task);
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
void exec_fn(void (*fn)(void));
|
void exec_fn(void (*fn)(void));
|
||||||
|
@ -12,7 +12,7 @@ struct task *current_task;
|
|||||||
void scheduler(void)
|
void scheduler(void)
|
||||||
{
|
{
|
||||||
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
|
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
|
||||||
void (*func[])(struct task *) = {remove_task, NULL, NULL, NULL,
|
void (*func[])(struct task *) = {zombify_task, NULL, NULL, NULL,
|
||||||
NULL, remove_task, kfork};
|
NULL, remove_task, kfork};
|
||||||
|
|
||||||
if (!current_task) // || current_task->next == current_task)
|
if (!current_task) // || current_task->next == current_task)
|
||||||
@ -20,7 +20,7 @@ void scheduler(void)
|
|||||||
cli();
|
cli();
|
||||||
struct task *it = current_task->next;
|
struct task *it = current_task->next;
|
||||||
while (it && it->status != RUN) {
|
while (it && it->status != RUN) {
|
||||||
if (it != current_task && func[it->status]) {
|
if (current_task->pid == 0 && func[it->status]) {
|
||||||
struct task *new_it = it->prev;
|
struct task *new_it = it->prev;
|
||||||
func[it->status](it);
|
func[it->status](it);
|
||||||
it = new_it;
|
it = new_it;
|
||||||
|
@ -63,23 +63,34 @@ void exec_fn(void (*fn)(void))
|
|||||||
new_task->eip = (u32 *)fn;
|
new_task->eip = (u32 *)fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void zombify_task(struct task *task)
|
||||||
|
{
|
||||||
|
cli(); // Technically useless
|
||||||
|
free_pages(task->heap, 4096);
|
||||||
|
free_pages(task->esp0, STACK_SIZE);
|
||||||
|
task->esp0 = NULL;
|
||||||
|
task->heap = NULL;
|
||||||
|
toris();
|
||||||
|
}
|
||||||
|
|
||||||
void remove_task(struct task *task)
|
void remove_task(struct task *task)
|
||||||
{
|
{
|
||||||
|
cli();
|
||||||
struct task *left = task->prev;
|
struct task *left = task->prev;
|
||||||
struct task *right = task->next;
|
struct task *right = task->next;
|
||||||
if (task->child)
|
|
||||||
|
if (task->child) {
|
||||||
remove_task(task->child);
|
remove_task(task->child);
|
||||||
|
task->child = NULL;
|
||||||
|
}
|
||||||
if (task->heap)
|
if (task->heap)
|
||||||
free_pages(task->heap, 4096);
|
free_pages(task->heap, 4096);
|
||||||
if (task->esp0)
|
if (task->esp0)
|
||||||
free_pages(task->esp0, STACK_SIZE);
|
free_pages(task->esp0, STACK_SIZE);
|
||||||
task->heap = NULL;
|
|
||||||
task->esp0 = NULL;
|
|
||||||
if (task->status != ZOMBIE) {
|
|
||||||
left->next = right;
|
left->next = right;
|
||||||
right->prev = left;
|
right->prev = left;
|
||||||
vfree(task);
|
vfree(task);
|
||||||
}
|
toris();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct task *copy_task(const struct task *task)
|
struct task *copy_task(const struct task *task)
|
||||||
@ -104,5 +115,5 @@ void exit_task(void)
|
|||||||
current_task->status = STOPPED;
|
current_task->status = STOPPED;
|
||||||
}
|
}
|
||||||
toris();
|
toris();
|
||||||
asm volatile("jmp scheduler");
|
scheduler();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user