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
a975c620
Commit
a975c620
authored
4 years ago
by
Elizabeth Baker
Browse files
Options
Downloads
Patches
Plain Diff
comments
parent
f4584982
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
allocate.c
+39
-4
39 additions, 4 deletions
allocate.c
with
39 additions
and
4 deletions
allocate.c
+
39
−
4
View file @
a975c620
...
@@ -49,6 +49,7 @@ void calStats(llist *completedProcesses, int *currentTime, float *aveTurnaroundT
...
@@ -49,6 +49,7 @@ void calStats(llist *completedProcesses, int *currentTime, float *aveTurnaroundT
void
addProcessToQueue
(
llist
*
processQueue
,
process
*
newProcess
,
int
currentTime
,
int
cpuID
);
void
addProcessToQueue
(
llist
*
processQueue
,
process
*
newProcess
,
int
currentTime
,
int
cpuID
);
process
*
getNextProcess
(
FILE
*
f
,
llist
*
arrivals
,
process
*
readAhead
);
process
*
getNextProcess
(
FILE
*
f
,
llist
*
arrivals
,
process
*
readAhead
);
process
*
getNextProcessB
(
FILE
*
f
,
llist
*
arrivals
,
process
*
readAhead
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -107,7 +108,7 @@ int main(int argc, char *argv[]) {
...
@@ -107,7 +108,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
B
(
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);
...
@@ -484,14 +485,16 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -484,14 +485,16 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
//add to arrivals until the readAhead is different
//add to arrivals until the readAhead is different
//memcpy(nextProcess,readAhead, sizeof(process));
//memcpy(nextProcess,readAhead, sizeof(process));
llist_add_inorder
(
readAhead
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
llist_add_inorder
(
readAhead
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
llist_print
(
arrivals
,(
void
(
*
)(
void
*
))
&
printQEntry
);
printf
(
"readAhead: %s
\n
"
,
readAhead
->
processID
);
printf
(
"readAhead: %s
\n
"
,
readAhead
->
processID
);
printf
(
"New Process: %s
\n
"
,
readAhead
->
processID
);
printf
(
"New Process: %s
\n
"
,
newProcess
->
processID
);
memcpy
(
readAhead
,
newProcess
,
sizeof
(
process
));
memcpy
(
readAhead
,
newProcess
,
sizeof
(
process
));
printf
(
"in if
\n
"
);
printf
(
"in if
\n
"
);
llist_print
(
arrivals
,(
void
(
*
)(
void
*
))
&
printQEntry
);
llist_print
(
arrivals
,(
void
(
*
)(
void
*
))
&
printQEntry
);
printf
(
"readAhead: %s
\n
"
,
readAhead
->
processID
);
printf
(
"readAhead: %s
\n
"
,
readAhead
->
processID
);
int
count
=
0
;
int
count
=
0
;
llist_print
(
arrivals
,
(
void
(
*
)(
void
*
))
&
printQEntry
);
while
(
newProcess
->
timeArrived
==
readAhead
->
timeArrived
){
while
(
newProcess
->
timeArrived
==
readAhead
->
timeArrived
){
//readAhead = nextProcess;
//readAhead = nextProcess;
//memcpy(nextProcess,readAhead, sizeof(process));
//memcpy(nextProcess,readAhead, sizeof(process));
...
@@ -505,7 +508,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -505,7 +508,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
){
if
(
fgets
(
line
,
sizeof
line
,
f
)
==
NULL
){
printf
(
"in while, end of file
\n
"
);
printf
(
"in while, end of file
\n
"
);
llist_print
(
arrivals
,(
void
(
*
)(
void
*
))
&
printQEntry
);
llist_print
(
arrivals
,(
void
(
*
)(
void
*
))
&
printQEntry
);
readAhead
->
timeArrived
=
-
1
;
readAhead
->
timeArrived
=
-
1
;
// Flag EOF
return
llist_pop
(
arrivals
);
return
llist_pop
(
arrivals
);
}
}
initializeProcess
(
line
,
newProcess
);
initializeProcess
(
line
,
newProcess
);
...
@@ -513,7 +516,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -513,7 +516,7 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
printf
(
"New Process: %s
\n
"
,
readAhead
->
processID
);
printf
(
"New Process: %s
\n
"
,
readAhead
->
processID
);
}
}
llist_print
(
arrivals
,
(
void
(
*
)(
void
*
))
&
printQEntry
);
//
llist_print(arrivals, (void (*)(void *)) &printQEntry);
//readAhead = nextProcess;
//readAhead = nextProcess;
memcpy
(
readAhead
,
nextProcess
,
sizeof
(
process
));
memcpy
(
readAhead
,
nextProcess
,
sizeof
(
process
));
...
@@ -530,3 +533,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -530,3 +533,35 @@ process *getNextProcess(FILE *f, llist *arrivals, process *readAhead) {
}
}
process
*
getNextProcessB
(
FILE
*
f
,
llist
*
arrivals
,
process
*
readAhead
)
{
char
line
[
36
];
process
*
newProcess
;
int
batchEnd
;
if
(
arrivals
!=
NULL
)
{
if
(
headData
(
arrivals
)
==
NULL
)
{
// no buffered processes so...{
// queue the next batch of arrivals - starting with the read ahead.
newProcess
=
malloc
(
sizeof
(
process
));
memcpy
(
newProcess
,
readAhead
,
sizeof
(
process
));
llist_add_inorder
(
newProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
while
(
readAhead
->
timeArrived
!=
-
1
&&
!
batchEnd
)
{
if
(
fgets
(
line
,
sizeof
line
,
f
)
!=
NULL
)
{
initializeProcess
(
line
,
newProcess
);
if
(
newProcess
->
timeArrived
==
readAhead
->
timeArrived
)
{
llist_add_inorder
(
newProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
}
else
{
batchEnd
=
-
1
;
memcpy
(
readAhead
,
newProcess
,
sizeof
(
process
));
}
}
else
{
readAhead
->
timeArrived
=
-
1
;
}
}
}
// now there's stuff in the arrivals lounge or there are no more to arrive
}
llist_print
(
arrivals
,
(
void
(
*
)(
void
*
))
&
printQEntry
);
return
llist_pop
(
arrivals
);
}
\ No newline at end of file
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