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; ...@@ -9,7 +9,7 @@ struct spinlock;
struct sleeplock; struct sleeplock;
struct stat; struct stat;
struct superblock; struct superblock;
struct timeVariables;
// bio.c // bio.c
void binit(void); void binit(void);
struct buf* bread(uint, uint); struct buf* bread(uint, uint);
...@@ -121,6 +121,7 @@ int wait(void); ...@@ -121,6 +121,7 @@ int wait(void);
void wakeup(void*); void wakeup(void*);
void yield(void); void yield(void);
void clockCounter(void); void clockCounter(void);
int waitForChild(struct timeVariables*);
// swtch.S // swtch.S
void swtch(struct context**, struct context*); void swtch(struct context**, struct context*);
......
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
int int
main(int argc,char **argv) main(int argc,char **argv)
{ {
...@@ -13,6 +12,10 @@ main(int argc,char **argv) ...@@ -13,6 +12,10 @@ main(int argc,char **argv)
//this code for test of 3.3 //this code for test of 3.3
/* /*
changePolicy(1); changePolicy(1);
changePolicy(2); changePolicy(2);*/
exit();*/
//for 3.4
//struct timeVariables * test;
// waitForChild();
exit();
} }
\ No newline at end of file
...@@ -88,6 +88,15 @@ allocproc(void) ...@@ -88,6 +88,15 @@ allocproc(void)
found: found:
p->state = EMBRYO; p->state = EMBRYO;
p->pid = nextpid++; 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); release(&ptable.lock);
...@@ -578,3 +587,48 @@ clockCounter(){ ...@@ -578,3 +587,48 @@ clockCounter(){
} }
release(&ptable.lock); 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); ...@@ -107,6 +107,7 @@ extern int sys_getChildren(void);
extern int sys_getCount(void); extern int sys_getCount(void);
extern int sys_changePriority(void); extern int sys_changePriority(void);
extern int sys_changePolicy(void); extern int sys_changePolicy(void);
extern int sys_waitForChild(void);
static int (*syscalls[])(void) = { static int (*syscalls[])(void) = {
[SYS_fork] sys_fork, [SYS_fork] sys_fork,
...@@ -134,6 +135,7 @@ static int (*syscalls[])(void) = { ...@@ -134,6 +135,7 @@ static int (*syscalls[])(void) = {
[SYS_getCount] sys_getCount, [SYS_getCount] sys_getCount,
[SYS_changePriority] sys_changePriority, [SYS_changePriority] sys_changePriority,
[SYS_changePolicy] sys_changePolicy, [SYS_changePolicy] sys_changePolicy,
[SYS_waitForChild] sys_waitForChild,
}; };
void void
......
...@@ -24,3 +24,4 @@ ...@@ -24,3 +24,4 @@
#define SYS_getCount 23 #define SYS_getCount 23
#define SYS_changePriority 24 #define SYS_changePriority 24
#define SYS_changePolicy 25 #define SYS_changePolicy 25
#define SYS_waitForChild 26
...@@ -164,6 +164,16 @@ sys_changePolicy(int mode){ ...@@ -164,6 +164,16 @@ sys_changePolicy(int mode){
return 1; 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 stat;
struct rtcdate; struct rtcdate;
struct timeVariables;
// system calls // system calls
int fork(void); int fork(void);
int exit(void) __attribute__((noreturn)); int exit(void) __attribute__((noreturn));
...@@ -27,6 +27,7 @@ int getChildren(int); ...@@ -27,6 +27,7 @@ int getChildren(int);
int getCount(int); int getCount(int);
int changePriority(int); int changePriority(int);
int changePolicy(int); int changePolicy(int);
int waitForChild(struct timeVariables*);
// ulib.c // ulib.c
int stat(const char*, struct stat*); int stat(const char*, struct stat*);
......
...@@ -32,4 +32,5 @@ SYSCALL(uptime) ...@@ -32,4 +32,5 @@ SYSCALL(uptime)
SYSCALL(getChildren) SYSCALL(getChildren)
SYSCALL(getCount) SYSCALL(getCount)
SYSCALL(changePriority) SYSCALL(changePriority)
SYSCALL(changePolicy) SYSCALL(changePolicy)
\ No newline at end of file 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