forked from yhzhang0128/egos-2000
-
Notifications
You must be signed in to change notification settings - Fork 0
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
10db455
commit a6ffdb4
Showing
6 changed files
with
110 additions
and
104 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
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
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,68 @@ | ||
/* | ||
* (C) 2022, Cornell University | ||
* All rights reserved. | ||
*/ | ||
|
||
/* Author: Yunhao Zhang | ||
* Description: process util functions | ||
*/ | ||
|
||
#include "egos.h" | ||
#include "grass.h" | ||
#include <string.h> | ||
|
||
static int proc_nprocs; | ||
extern int proc_curr_idx; | ||
extern struct process proc_set[MAX_NPROCESS]; | ||
|
||
void intr_entry(int id); | ||
|
||
void proc_init() { | ||
earth->intr_register(intr_entry); | ||
|
||
proc_nprocs = 0; | ||
memset(proc_set, 0, sizeof(struct process) * MAX_NPROCESS); | ||
|
||
/* the first process is now running */ | ||
proc_alloc(); | ||
proc_curr_idx = 0; | ||
proc_set_running(PID(proc_curr_idx)); | ||
} | ||
|
||
int proc_alloc() { | ||
proc_nprocs++; | ||
for (int i = 0; i < MAX_NPROCESS; i++) { | ||
if (proc_set[i].pid == 0) { | ||
proc_set[i].pid = proc_nprocs; | ||
proc_set[i].status = PROC_UNUSED; | ||
return proc_nprocs; | ||
} | ||
} | ||
FATAL("Reach the limit of %d processes", MAX_NPROCESS); | ||
return -1; | ||
} | ||
|
||
void proc_free(int pid) { | ||
FATAL("proc_free not implemented"); | ||
} | ||
|
||
static void proc_set_status(int pid, int status) { | ||
for (int i = 0; i < MAX_NPROCESS; i++) { | ||
if (proc_set[i].pid == pid) { | ||
proc_set[i].status = status; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
void proc_set_ready(int pid) { | ||
proc_set_status(pid, PROC_READY); | ||
} | ||
|
||
void proc_set_running(int pid) { | ||
proc_set_status(pid, PROC_RUNNING); | ||
} | ||
|
||
void proc_set_runnable(int pid) { | ||
proc_set_status(pid, PROC_RUNNABLE); | ||
} |
This file was deleted.
Oops, something went wrong.