This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7f4502
commit b55ab70
Showing
8 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stddef.h> | ||
#include "sched.h" | ||
#include "../common/common.h" | ||
#include "process.h" | ||
#include "../mm/kmem.h" | ||
|
||
static struct process_ll *PROCESSES = NULL; | ||
|
||
void sched_init(void) { | ||
ASSERT(PROCESSES == NULL, | ||
"sched_init(): should only be called once at system startup\n"); | ||
sched_enqueue(init_process); | ||
} | ||
|
||
void sched_enqueue(void (*func)(void)) { | ||
struct process_ll *nd = kmalloc(sizeof(struct process_ll)); | ||
ASSERT(nd != NULL, | ||
"sched_enqueue(): failed to allocate linked list node for new process\n"); | ||
nd->process = create_process(func); | ||
if (PROCESSES == NULL) { | ||
nd->prev = nd; | ||
nd->next = nd; | ||
PROCESSES = nd; | ||
} else { | ||
nd->prev = PROCESSES->prev; | ||
nd->next = PROCESSES; | ||
PROCESSES->prev->next = nd; | ||
PROCESSES->prev = nd; | ||
} | ||
} | ||
|
||
struct process *sched_schedule(void) { | ||
ASSERT(PROCESSES != NULL, | ||
"sched_schedule(): cannot schedule a process from an empty process list - did you call sched_init()?\n"); | ||
struct process *process = PROCESSES->process; | ||
ASSERT(process != NULL, | ||
"sched_schedule(): process structure from head of process list was unexpectedly NULL\n"); | ||
PROCESSES = PROCESSES->next; | ||
return process; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef SCHED_H | ||
#define SCHED_H | ||
|
||
struct process_ll { | ||
struct process *process; | ||
struct process_ll *prev; | ||
struct process_ll *next; | ||
}; | ||
|
||
void sched_init(void); | ||
void sched_enqueue(void (*)(void)); | ||
struct process *sched_schedule(void); | ||
|
||
#endif |