Commit 3daba6c2 authored by Amir Hosein Kashani's avatar Amir Hosein Kashani

3.4 is finnishe and some bugs fixed

parent aad062e1
......@@ -9,7 +9,7 @@ struct spinlock;
struct sleeplock;
struct stat;
struct superblock;
struct timeVariables;
// bio.c
void binit(void);
struct buf* bread(uint, uint);
......@@ -121,6 +121,7 @@ int wait(void);
void wakeup(void*);
void yield(void);
void clockCounter(void);
int waitForChild(struct timeVariables*);
// swtch.S
void swtch(struct context**, struct context*);
......
#include "types.h"
#include "stat.h"
#include "user.h"
int
main(int argc,char **argv)
{
......@@ -13,6 +12,10 @@ main(int argc,char **argv)
//this code for test of 3.3
/*
changePolicy(1);
changePolicy(2);
exit();*/
changePolicy(2);*/
//for 3.4
//struct timeVariables * test;
// waitForChild();
exit();
}
\ No newline at end of file
......@@ -88,6 +88,15 @@ allocproc(void)
found:
p->state = EMBRYO;
p->pid = nextpid++;
p->priority = 5;
p->calculatedPriority = 5;
struct proc *p1;
for(p1 = ptable.proc; p1 < &ptable.proc[NPROC]; p1++){
if(p1->priority < p->calculatedPriority){
p->calculatedPriority = p1->priority;
}
}
release(&ptable.lock);
......@@ -578,3 +587,48 @@ clockCounter(){
}
release(&ptable.lock);
}
int
waitForChild(struct timeVariables* input)
{
struct proc *p;
int havekids, pid;
struct proc *curproc = myproc();
acquire(&ptable.lock);
for(;;){
// Scan through table looking for exited children.
havekids = 0;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->parent != curproc)
continue;
havekids = 1;
if(p->state == ZOMBIE){
// Found one.
pid = p->pid;
kfree(p->kstack);
p->kstack = 0;
freevm(p->pgdir);
p->pid = 0;
p->parent = 0;
p->name[0] = 0;
p->killed = 0;
p->state = UNUSED;
*input = p->timeHandeler;
release(&ptable.lock);
return pid;
}
}
// No point waiting if we don't have any children.
if(!havekids || curproc->killed){
release(&ptable.lock);
return -1;
}
// Wait for children to exit. (See wakeup1 call in proc_exit.)
sleep(curproc, &ptable.lock); //DOC: wait-sleep
}
}
\ No newline at end of file
......@@ -107,6 +107,7 @@ extern int sys_getChildren(void);
extern int sys_getCount(void);
extern int sys_changePriority(void);
extern int sys_changePolicy(void);
extern int sys_waitForChild(void);
static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
......@@ -134,6 +135,7 @@ static int (*syscalls[])(void) = {
[SYS_getCount] sys_getCount,
[SYS_changePriority] sys_changePriority,
[SYS_changePolicy] sys_changePolicy,
[SYS_waitForChild] sys_waitForChild,
};
void
......
......@@ -24,3 +24,4 @@
#define SYS_getCount 23
#define SYS_changePriority 24
#define SYS_changePolicy 25
#define SYS_waitForChild 26
......@@ -164,6 +164,16 @@ sys_changePolicy(int mode){
return 1;
}
//3.4
int
sys_waitForChild(void){
struct timeVariables *ct;
argptr (0 , (void*)&ct ,sizeof(*ct));
waitForChild(ct);
cprintf("%d",ct->readyTime);
return 1;
}
......
struct stat;
struct rtcdate;
struct timeVariables;
// system calls
int fork(void);
int exit(void) __attribute__((noreturn));
......@@ -27,6 +27,7 @@ int getChildren(int);
int getCount(int);
int changePriority(int);
int changePolicy(int);
int waitForChild(struct timeVariables*);
// ulib.c
int stat(const char*, struct stat*);
......
......@@ -33,3 +33,4 @@ SYSCALL(getChildren)
SYSCALL(getCount)
SYSCALL(changePriority)
SYSCALL(changePolicy)
SYSCALL(waitForChild)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment