Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30023-2021-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elizabeth Baker
comp30023-2021-project-1
Commits
2ff27b06
Commit
2ff27b06
authored
Mar 28, 2021
by
Elizabeth Baker
Browse files
Options
Downloads
Patches
Plain Diff
buffProc - working
parent
b1c1e252
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
allocate.c
+18
-20
18 additions, 20 deletions
allocate.c
with
18 additions
and
20 deletions
allocate.c
+
18
−
20
View file @
2ff27b06
...
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
...
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
//while (fgets(line, sizeof line, f) != NULL) {
//while (fgets(line, sizeof line, f) != NULL) {
while
(
newProcess
=
getNextProcess
(
f
,
arrivalLounge
,
readAhead
))
{
while
(
newProcess
=
getNextProcess
(
f
,
arrivalLounge
,
readAhead
))
{
printf
(
"process id:%s process arrival time: %d
\n
"
,
newProcess
->
processID
,
newProcess
->
timeArrived
);
//
printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived);
deltaTime
=
newProcess
->
timeArrived
-
currentTime
;
deltaTime
=
newProcess
->
timeArrived
-
currentTime
;
...
@@ -186,7 +186,7 @@ int main(int argc, char *argv[]) {
...
@@ -186,7 +186,7 @@ int main(int argc, char *argv[]) {
}
}
// No more processes to be read in, just need to finish the ones in the queues
// No more processes to be read in, just need to finish the ones in the queues
printf
(
"No more processes to be read in
\n
"
);
//
printf("No more processes to be read in\n");
int
tr
;
int
tr
;
while
(
numProcessesLeft
)
{
while
(
numProcessesLeft
)
{
// find how big the next time step is - its the smallest of the times remaining on each queue's head process
// find how big the next time step is - its the smallest of the times remaining on each queue's head process
...
@@ -227,8 +227,8 @@ int main(int argc, char *argv[]) {
...
@@ -227,8 +227,8 @@ int main(int argc, char *argv[]) {
// currentTime += deltaTime;
// currentTime += deltaTime;
}
}
printf
(
"Completed Queue:"
);
//
printf("Completed Queue:");
llist_print
(
completedProcesses
,
(
void
(
*
)(
void
*
))
&
printQEntry
);
//
llist_print(completedProcesses, (void (*)(void *)) &printQEntry);
calStats
(
completedProcesses
,
&
currentTime
,
&
averageTurnaroundTime
,
&
maxOverhead
,
&
averageOverhead
);
calStats
(
completedProcesses
,
&
currentTime
,
&
averageTurnaroundTime
,
&
maxOverhead
,
&
averageOverhead
);
...
@@ -442,34 +442,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -442,34 +442,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
if
(
arrivals
==
NULL
)
{
if
(
arrivals
==
NULL
)
{
perror
(
"list is NULL"
);
perror
(
"list is NULL"
);
return
NULL
;
}
}
if
(
headProcess
!=
NULL
){
headProcess
=
headData
(
arrivals
);
if
(
headProcess
!=
NULL
){
//thare are processes in arrivals
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
}
//checking if at the end of the file
//checking if at the end of the file
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
&&
readAhead
!=
NULL
)
{
//read EOF && readAhead != NULL
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
&&
readAhead
->
timeArrived
!=
-
1
)
{
//read EOF && readAhead != NULL
memcpy
(
nextProcess
,
readAhead
,
sizeof
(
process
));
memcpy
(
nextProcess
,
readAhead
,
sizeof
(
process
));
llist_add_inorder
(
nextProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
llist_add_inorder
(
nextProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
readAhead
=
NULL
;
readAhead
->
timeArrived
=
-
1
;
free
(
readAhead
);
//initializeProcess(NULL,readAhead);
//initializeProcess(NULL,readAhead);
if
(
headData
(
arrivals
)
!=
NULL
)
{
//have read EOF but still arrivals
if
(
headData
(
arrivals
)
!=
NULL
)
{
//have read EOF but still arrivals
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
else
if
(
headData
(
arrivals
)
==
NULL
)
{
//have read EOF; all arrivals dealt with
}
else
if
(
headData
(
arrivals
)
==
NULL
)
{
//have read EOF; all arrivals dealt with
return
readAhead
;
return
NULL
;
}
}
}
else
if
(
readAhead
==
NULL
&&
headData
(
arrivals
)
!=
NULL
)
{
//have read EOF but still arrivals
}
else
if
(
readAhead
->
timeArrived
==
-
1
&&
headData
(
arrivals
)
!=
NULL
)
{
//have read EOF but still arrivals
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
else
if
(
readAhead
==
NULL
&&
headData
(
arrivals
)
==
NULL
)
{
//have read EOF; all arrivals dealt with
}
else
if
(
readAhead
->
timeArrived
==
-
1
&&
headData
(
arrivals
)
==
NULL
)
{
//have read EOF; all arrivals dealt with
return
readAhead
;
return
NULL
;
}
else
{
// Normal case
}
else
{
// Normal case
initializeProcess
(
line
,
newProcess
);
initializeProcess
(
line
,
newProcess
);
}
}
//headProcess = headData(arrivals);
headProcess
=
headData
(
arrivals
);
if
(
headProcess
==
NULL
){
//no one in the arrivals lounge
if
(
headProcess
==
NULL
){
//no one in the arrivals lounge
//same start time
//same start time
if
(
newProcess
->
timeArrived
==
readAhead
->
timeArrived
){
if
(
newProcess
->
timeArrived
==
readAhead
->
timeArrived
){
...
@@ -479,7 +480,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -479,7 +480,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
readAhead
=
nextProcess
;
readAhead
=
nextProcess
;
//EOF the file assign readAhead to null then return pop(arrivals)
//EOF the file assign readAhead to null then return pop(arrivals)
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
){
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
){
readAhead
=
NULL
;
readAhead
->
timeArrived
=
-
1
;
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
}
initializeProcess
(
line
,
newProcess
);
initializeProcess
(
line
,
newProcess
);
...
@@ -488,16 +489,13 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -488,16 +489,13 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
readAhead
=
nextProcess
;
readAhead
=
nextProcess
;
//if the readAhead is differnt
//if the readAhead is differnt
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
else
{
//diff start time
}
else
{
//diff start time
// nextProcess = readAhead;
memcpy
(
nextProcess
,
readAhead
,
sizeof
(
process
));
memcpy
(
nextProcess
,
readAhead
,
sizeof
(
process
));
memcpy
(
readAhead
,
newProcess
,
sizeof
(
process
));
memcpy
(
readAhead
,
newProcess
,
sizeof
(
process
));
printf
(
"Proc %s: Arrival: %d
\n
"
,
nextProcess
->
processID
,
nextProcess
->
timeArrived
);
return
nextProcess
;
return
nextProcess
;
}
}
}
else
{
//there are arrivals
return
llist_pop
(
arrivals
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment