-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.c
More file actions
195 lines (192 loc) · 4.78 KB
/
utility.c
File metadata and controls
195 lines (192 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Host Dispatcher Shell Project for SOFE 3950U / CSCI 3020U: Operating Systems
*
* Copyright (C) 2015, <GROUP MEMBERS>
* All rights reserved.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "utility.h"
#include "queue.h"
extern struct queue *root0;
extern struct queue *root1;
extern struct queue *root2;
extern struct queue *root3;
extern struct queue *conductor0;
extern struct queue *conductor1;
extern struct queue *conductor2;
extern struct queue *conductor3;
extern struct resources res;
// Define your utility functions here, you will likely need to add more...
int termination[4];
int alloc_mem(int memory,int priority){
int count=0;
int index=0;
for (int x = 0; x < MEMORY; x++){
if (res.memory[x]==0){
res.memory[x]=1;
//printf("found one\n");
count++;
}
else{
for (int y = index; y < (index+count); y++){
res.memory[y]=0;
//printf("reset");
}
count=0;
index=x+1;
}
if (count==memory){
printf("found space\n");
return index;
}
}
printf("searching for process to delete\n");
if (priority==0){
int address=8080;
conductor0 = root0;
while (1){
if (priority<=conductor0->process.priority &&conductor0->process.address!=8080 &&conductor0->process.memory >=memory){
address=conductor0->process.address;
if(conductor0->process.memory>memory){
for (int y = (address+memory); y < (address+conductor0->process.memory); y++){
resources.memory[y]=0;
}
}
conductor0->process.address=8080;
printf("found address\n");
return address;
}
if(conductor0->next != 0){
//printf("looping");
conductor0 = conductor0->next;
continue;
}
else{
//printf("could not find address\n");
return address;
}
}
}
if (priority==1){
int address=8080;
conductor1 = root1;
while (1){
if (priority<=conductor1->process.priority &&conductor1->process.address!=8080 &&conductor1->process.memory >=memory){
address=conductor1->process.address;
if(conductor1->process.memory>memory){
for (int y = (address+memory); y < (address+conductor1->process.memory); y++){
resources.memory[y]=0;
}
}
conductor1->process.address=8080;
printf("found address\n");
return address;
}
if(conductor1->next != 0){
conductor1 = conductor1->next;
continue;
}
else{
//printf("could not find address\n");
return address;
}
}
}
if (priority==2){
int address=8080;
conductor2 = root2;
while (1){
if (priority<=conductor2->process.priority &&conductor2->process.address!=8080 &&conductor2->process.memory >=memory){
address=conductor2->process.address;
if(conductor2->process.memory>memory){
for (int y = (address+memory); y < (address+conductor2->process.memory); y++){
resources.memory[y]=0;
}
}
conductor2->process.address=8080;
printf("found address\n");
return address;
}
if(conductor2->next != 0){
conductor2 = conductor2->next;
continue;
}
else{
//printf("could not find address\n");
return address;
}
}
}
else{
int address=8080;
conductor3 = root3;
while (1){
if (priority<=conductor3->process.priority &&conductor3->process.address!=8080 &&conductor0->process.memory >=memory){
address=conductor3->process.address;
if(conductor3->process.memory>memory){
for (int y = (address+memory); y < (address+conductor3->process.memory); y++){
resources.memory[y]=0;
}
}
conductor3->process.address=8080;
printf("found address\n");
return address;
}
if(conductor3->next != 0){
conductor3 = conductor3->next;
continue;
}
else{
//printf("could not find address\n");
return address;
}
}
}
}
void free_mem(int index, int memory){
int count=0;
for (int x = index; count < memory; x++){
res.memory[x]=0;
count++;
}
}
void makeT(){
termination[0]=0;
termination[1]=0;
termination[2]=0;
termination[3]=0;
conductor0 = root0;
conductor1 = root1;
conductor2 = root2;
conductor3 = root3;
if ( conductor0 != 0 ) { /* Makes sure there is a place to start */
while ( conductor0->next != 0 ) {
termination[0]+=1;
conductor0 = conductor0->next;
}
//termination[0]+=1;
}
if ( conductor1 != 0 ) { /* Makes sure there is a place to start */
while ( conductor1->next != 0 ) {
termination[1]+=1;
conductor1 = conductor1->next;
}
//termination[1]+=1;
}
if ( conductor2 != 0 ) { /* Makes sure there is a place to start */
while ( conductor2->next != 0 ) {
termination[2]+=1;
conductor2 = conductor2->next;
}
//termination[2]+=1;
}
if ( conductor3 != 0 ) { /* Makes sure there is a place to start */
while ( conductor3->next != 0 ) {
termination[3]+=1;
conductor3 = conductor3->next;
}
//termination[3]+=1;
}
}