From: Matthias Kruk Date: Mon, 25 Nov 2019 07:20:32 +0000 (+0900) Subject: Add sched_task_resume() function X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=7986a66c03205b3b445b77d1a712c2f0e1f7c3ff;p=corax Add sched_task_resume() function --- diff --git a/kernel/core/sched.c b/kernel/core/sched.c index 15a8a0f..1d73477 100644 --- a/kernel/core/sched.c +++ b/kernel/core/sched.c @@ -257,3 +257,34 @@ int sched_task_suspend(task_t *t) return(ret_val); } + +int sched_task_resume(task_t *t) +{ + int ret_val; + + /* + * Make sure the task is currently in the TASK_STATE_WAITING state. + * If it is, change its state to TASK_STATE_READY. + */ + task_lock(t); + + if(t->t_state == TASK_STATE_WAITING) { + t->t_state = TASK_STATE_READY; + ret_val = 0; + } else { + ret_val = -EBUSY; + } + + task_unlock(t); + + /* if the task was waiting, remove it from the waitq and add it to the readyq */ + if(!ret_val) { + ret_val = _unq(&_waitq, t); + + if(ret_val >= 0) { + _nq(&_readyq, t); + } + } + + return(ret_val); +} diff --git a/kernel/include/sched.h b/kernel/include/sched.h index 4f54bea..65efeb9 100644 --- a/kernel/include/sched.h +++ b/kernel/include/sched.h @@ -9,5 +9,6 @@ int sched_enqueue(task_t*); int sched_dequeue(task_t*); int sched_signal(pid_t); int sched_task_suspend(task_t*); +int sched_task_resume(task_t*); #endif /* __CORE_SCHED_H */