diff --git a/kernel/sched.c b/kernel/sched.c index 0320f36d08d6d8094859aa1b7c951ce737aa367b..e279768f2805ddebf4530c90e68ece225fffab52 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -61,7 +61,50 @@ void schedule() { switch_to(next); } -int clock = COUNTER; +static inline void __sleep_on(struct task_struct** p, int state) { + struct task_struct* tmp; + + if (!p) + return; + if (current == &(init_task.task)) + printk("task[0] trying to sleep"); + + tmp = *p; + *p = current; + current->state = state; + +repeat: + schedule(); + + if (*p && *p != current) { + (**p).state = 0; + current->state = TASK_UNINTERRUPTIBLE; + goto repeat; + } + + if (!*p) + printk("Warning: *P = NULL\n\r"); + if (*p = tmp) + tmp->state = 0; +} + +void interruptible_sleep_on(struct task_struct** p) { + __sleep_on(p, TASK_INTERRUPTIBLE); +} + +void sleep_on(struct task_struct** p) { + __sleep_on(p, TASK_UNINTERRUPTIBLE); +} + +void wake_up(struct task_struct **p) { + if (p && *p) { + if ((**p).state == TASK_STOPPED) + printk("wake_up: TASK_STOPPED"); + if ((**p).state == TASK_ZOMBIE) + printk("wake_up: TASK_ZOMBIE"); + (**p).state=0; + } +} void do_timer(long cpl) { if ((--current->counter)>0) return;