1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

kernel/tasks: implement function to get process control block by ID

This commit is contained in:
daniel-k 2016-07-01 18:52:28 +02:00
parent 78eecc9ec1
commit f93e66b4df
2 changed files with 32 additions and 0 deletions

View file

@ -190,6 +190,18 @@ int wakeup_task(tid_t);
*/
int block_current_task(void);
/** @brief Get a process control block
*
* @param id ID of the task to retrieve
* @param task Location to store pointer to task
* @return
* - 0 on success
* - -ENOMEM (-12) if @p task is NULL
* - -ENOENT ( -2) if @p id not in task table
* - -EINVAL (-22) if there's no valid task with @p id
*/
int get_task(tid_t id, task_t** task);
/** @brief Block current task until timer expires
*
* @param deadline Clock tick, when the timer expires

View file

@ -877,6 +877,26 @@ get_task_out:
return NULL;
}
int get_task(tid_t id, task_t** task)
{
if (BUILTIN_EXPECT(task == NULL, 0)) {
return -ENOMEM;
}
if (BUILTIN_EXPECT(id >= MAX_TASKS, 0)) {
return -ENOENT;
}
if (BUILTIN_EXPECT(task_table[id].status == TASK_INVALID, 0)) {
return -EINVAL;
}
*task = &task_table[id];
return 0;
}
void reschedule(void)
{
size_t** stack;