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:
parent
78eecc9ec1
commit
f93e66b4df
2 changed files with 32 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue