[go: nahoru, domu]

Skip to content

Commit

Permalink
fix scheduling bug that was triggered when a single process available
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Dec 20, 2021
1 parent 704d2ba commit 864a1e4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/kernel/task/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ static void move_end_of_list(struct task_list_t *element) {

if (head->next == NULL) {
head->next = element;
element->next = NULL;
} else {
struct task_list_t *tmp = this_rq()->tasks;
/* find list's tail */
Expand All @@ -61,10 +60,10 @@ static void move_end_of_list(struct task_list_t *element) {
}

tmp->next = element;
this_rq()->tasks = element->next;
element->next = NULL;
}

element->next = NULL;

}

void scheduler_add(task_struct_t *task) {
Expand All @@ -84,15 +83,18 @@ void schedule(interrupt_stack_frame_t *int_frame) {
struct task_list_t *head = this_rq()->tasks;

/* fail-fast if there is nothing else to run */
if ((this_rq()->curr != NULL && head->next == NULL) || head == NULL)
if (!head || (this_rq()->curr && !head->next))
return;

task_struct_t *curr = this_rq()->curr;
task_struct_t *next = head->val;

/* puts current process at the end of list to
* give a change for the other tasks to run */
move_end_of_list(head);
if (head->next) {
this_rq()->tasks = head->next;
move_end_of_list(head);
}

/* select process to be executed */
this_rq()->curr = next;
Expand Down

0 comments on commit 864a1e4

Please sign in to comment.