Skip to content

Commit

Permalink
Make some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
GuochiGu committed Jun 13, 2018
1 parent bb567b8 commit 88861c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void userinit(void);
int wait(void);
void wakeup(void*);
void yield(void);
int getprocinfo(int*, char**, int*, uint*);
int getprocinfo(int*, char(*)[16], int*, uint*);

// swtch.S
void swtch(struct context**, struct context*);
Expand Down
2 changes: 1 addition & 1 deletion proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ procdump(void)
}

int
getprocinfo(int *pid, char **name, int *state, uint *sz)
getprocinfo(int *pid, char (*name)[16], int *state, uint *sz)
{
struct proc p;
int i, j;
Expand Down
2 changes: 1 addition & 1 deletion sysproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int
sys_getprocinfo(void)
{
int *pid;
char **name;
char (*name)[16];
int *state;
uint *sz;

Expand Down
22 changes: 14 additions & 8 deletions taskmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const char procstate[6][9] = {"UNUSED", "EMBRYO", "SLEEPING", "RUNNABLE", "RUNNI

char buff[96][80];
int curline = 4; //表示当前高亮显示的行序号,范围4-19
int curpage = 1; //表示当前页码,范围1-4
int curpage = 0; //表示当前页码,范围0-3
int procID[NPROC];
char procName[NPROC][16];
int procState[NPROC];
Expand All @@ -31,9 +31,11 @@ void calsTaskMgrInfo(void);
void
runTaskMgr(void)
{
static char buf[2];
char buf[2];
char *c;

calsTaskMgrInfo();
updscrcont(buff[curpage*24], curline);
while(getCmd(buf) >= 0)
{
/*
Expand All @@ -47,7 +49,7 @@ runTaskMgr(void)
c = buf;
procCmd(c);
calsTaskMgrInfo();
updscrcont(buff[(curpage-1)*24], curline);
updscrcont(buff[curpage*24], curline);
}
}

Expand All @@ -74,21 +76,21 @@ procCmd(char *cmd)
curline++;
break;
case KEY_LF:
if(curpage > 1)
if(curpage > 0)
curpage--;
break;
case KEY_RT:
if(curpage < 4)
if(curpage < 3)
curpage++;
break;
case 'k':
if(strcmp("taskmgr", procName[(curpage-1)*16+(curline-4)]) == 0){
if(strcmp("taskmgr", procName[curpage*16+curline-4]) == 0){
closetaskmgr();
exit();
break;
}
else{
kill(procID[(curpage-1)*16+(curline-4)]);
kill(procID[curpage*16+curline-4]);
break;
}
case 'q':
Expand Down Expand Up @@ -116,7 +118,11 @@ fork2(void)
void
calsTaskMgrInfo(void)
{
getprocinfo(procID, (char **)procName, procState, procSize);
int i, j;
getprocinfo(procID, procName, procState, procSize);
for(i = 0; i < 96; i++)
for(j = 0; j < 80; j++)
buff[i][j] = '1';
}

/*
Expand Down
2 changes: 1 addition & 1 deletion user.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int sleep(int);
int uptime(void);
int inittaskmgr(void);
int closetaskmgr(void);
int getprocinfo(int*, char**, int*, uint*);
int getprocinfo(int*, char(*)[16], int*, uint*);
int updscrcont(char*, int);

// ulib.c
Expand Down

0 comments on commit 88861c8

Please sign in to comment.