Function comments (v1)
This commit is contained in:
@@ -23,13 +23,22 @@ extern uint64_t *kernel_pml4;
|
||||
|
||||
size_t next_free_pid = 0;
|
||||
|
||||
/*
|
||||
* process_init - Initializes process list
|
||||
*/
|
||||
void process_init()
|
||||
{
|
||||
processes_list = NULL;
|
||||
current_process = NULL;
|
||||
}
|
||||
|
||||
// Only for debug
|
||||
/*
|
||||
* process_display_list - Debug function to display processes
|
||||
* @processes_list: head of the process linked list
|
||||
*
|
||||
* This function prints the linked list of processes
|
||||
* to the DEBUG output.
|
||||
*/
|
||||
void process_display_list(struct process_t* processes_list)
|
||||
{
|
||||
int process_view_id = 0;
|
||||
@@ -42,6 +51,19 @@ void process_display_list(struct process_t* processes_list)
|
||||
DEBUG("NULL");
|
||||
}
|
||||
|
||||
/*
|
||||
* process_create - Create a process
|
||||
* @name: name of the process
|
||||
* @function: beginning of process executable code
|
||||
* @arg: (optional) argument provided to process
|
||||
*
|
||||
* This function creates a process, gives it all
|
||||
* necessary context and a stack, and adds the
|
||||
* process to the linked list.
|
||||
*
|
||||
* Return:
|
||||
* <proc> - pointer to created process
|
||||
*/
|
||||
struct process_t* process_create(char* name, void(*function)(void*), void* arg)
|
||||
{
|
||||
CLEAR_INTERRUPTS;
|
||||
@@ -81,6 +103,11 @@ struct process_t* process_create(char* name, void(*function)(void*), void* arg)
|
||||
return proc;
|
||||
}
|
||||
|
||||
/*
|
||||
* process_add - Add a process to the end of the linked list
|
||||
* @processes_list: pointer to the head of the linked list
|
||||
* @process: process to add at the end of the linked list
|
||||
*/
|
||||
void process_add(struct process_t** processes_list, struct process_t* process)
|
||||
{
|
||||
if (!process) return;
|
||||
@@ -100,6 +127,11 @@ void process_add(struct process_t** processes_list, struct process_t* process)
|
||||
tmp->next = process;
|
||||
}
|
||||
|
||||
/*
|
||||
* process_delete - Delete a process from the linked list
|
||||
* @processes_list: pointer to head of linked list
|
||||
* @process: the process to delete from the list
|
||||
*/
|
||||
void process_delete(struct process_t** processes_list, struct process_t* process)
|
||||
{
|
||||
if (!processes_list || !*processes_list || !process) return;
|
||||
@@ -128,14 +160,30 @@ void process_delete(struct process_t** processes_list, struct process_t* process
|
||||
kfree(process);
|
||||
}
|
||||
|
||||
/*
|
||||
* process_get_next - Get the next process (unused)
|
||||
* @process: pointer to process
|
||||
*
|
||||
* Return:
|
||||
* <process->next> - process right after the one specified
|
||||
*/
|
||||
struct process_t* process_get_next(struct process_t* process)
|
||||
{
|
||||
if (!process) return NULL;
|
||||
return process->next;
|
||||
}
|
||||
|
||||
// Will be used to clean up resources (if any, when we implement it)
|
||||
// Just mark as DEAD then idle. Scheduler will delete process at next timer interrupt % quantum.
|
||||
/*
|
||||
* process_exit - Exit from a process
|
||||
*
|
||||
* This function is pushed to all process stacks, as a last
|
||||
* return address. Once the process is done executing, it
|
||||
* ends up here.
|
||||
*
|
||||
* Process is marked as DEAD, and then execution loops.
|
||||
* Next time the scheduler sees the process, it will
|
||||
* automatically delete it from the linked list.
|
||||
*/
|
||||
void process_exit()
|
||||
{
|
||||
DEBUG("Exiting from process '%s'", current_process->name);
|
||||
|
||||
@@ -14,12 +14,24 @@ extern struct process_t* processes_list;
|
||||
extern struct process_t* current_process;
|
||||
extern struct process_t* idle_proc;
|
||||
|
||||
/*
|
||||
* scheduler_init - Choose the first process
|
||||
*/
|
||||
void scheduler_init()
|
||||
{
|
||||
// Choose first process?
|
||||
current_process = processes_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* scheduler_schedule - Main scheduling routine
|
||||
* @context: CPU context of previous process
|
||||
*
|
||||
* Chooses the next process that we should run.
|
||||
* The routine is executed every SCHEDULER_QUANTUM ticks.
|
||||
*
|
||||
* Return:
|
||||
* <context> - CPU context for next process
|
||||
*/
|
||||
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
|
||||
{
|
||||
if (context == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user