Skip to content

Commit 707eb20

Browse files
setQueue system call added
1 parent d65d6b8 commit 707eb20

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

defs.h

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ int getTurnAroundTime(int pid);
132132
int getWaitingTime(int pid);
133133
int getCBT(int pid);
134134
int customWait(int *procTimes);
135+
int setQueue(int queueNumber);
135136

136137
// swtch.S
137138
void swtch(struct context **, struct context *);

proc.c

+15
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ allocproc(void)
121121
p->sleeping_t = 0;
122122
p->runnable_t = 0;
123123
p->running_t = 0;
124+
p->queue = 0; // by default each process is in the 0 queue
124125

125126
p->rr_remaining_t = QUANTUM;
126127
p->priority = DEFAULT_PRIORITY;
@@ -792,4 +793,18 @@ int customWait(int *procTimes)
792793
// Wait for children to exit. (See wakeup1 call in proc_exit.)
793794
sleep(curproc, &ptable.lock); //DOC: wait-sleep
794795
}
796+
}
797+
798+
int setQueue(int queueNumber)
799+
{
800+
struct proc *curproc = myproc();
801+
if (queueNumber > 4 || queueNumber < 1)
802+
{
803+
return -1;
804+
}
805+
else
806+
{
807+
curproc->queue = queueNumber;
808+
return 0;
809+
}
795810
}

proc.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct proc
6060
struct file *ofile[NOFILE]; // Open files
6161
struct inode *cwd; // Current directory
6262
char name[16]; // Process name (debugging)
63+
int queue; // Defines in which queue the process belongs
6364

6465
// stores how many times each of the syscalls has been called
6566
int syscallsCount[NSYSCALLS];

syscall.c

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern int sys_getTurnAroundTime(void);
108108
extern int sys_getWaitingTime(void);
109109
extern int sys_getCBT(void);
110110
extern int sys_customWait(void);
111+
extern int sys_setQueue(void);
111112

112113
static int (*syscalls[])(void) = {
113114
[SYS_fork] sys_fork,
@@ -140,6 +141,7 @@ static int (*syscalls[])(void) = {
140141
[SYS_getWaitingTime] sys_getWaitingTime,
141142
[SYS_getCBT] sys_getCBT,
142143
[SYS_customWait] sys_customWait,
144+
[SYS_setQueue] sys_setQueue,
143145

144146
};
145147

syscall.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
#define SYS_getWaitingTime 28
3030
#define SYS_getCBT 29
3131
#define SYS_customWait 30
32+
#define SYS_setQueue 31
3233

sysproc.c

+12
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,16 @@ int sys_customWait(void)
171171
{
172172
return customWait(procTimes);
173173
}
174+
}
175+
176+
int sys_setQueue(void)
177+
{
178+
int queueNumber;
179+
if (argint(0, &queueNumber) < 0)
180+
{
181+
return -1;
182+
}
183+
else
184+
return setQueue(queueNumber);
185+
174186
}

user.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ int getTurnAroundTime(int pid);
3232
int getWaitingTime(int pid);
3333
int getCBT(int pid);
3434
int customWait(int *procTimes);
35+
int setQueue(int queueNumber);
36+
3537

3638
// ulib.c
3739
int stat(const char *, struct stat *);

usys.S

+3
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ SYSCALL(changePolicy)
3737
SYSCALL(getTurnAroundTime)
3838
SYSCALL(getWaitingTime)
3939
SYSCALL(getCBT)
40+
int setQueue(int queueNumber);
4041
SYSCALL(customWait)
42+
SYSCALL(setQueue)
43+

0 commit comments

Comments
 (0)