Skip to content

Commit

Permalink
Fix wait().
Browse files Browse the repository at this point in the history
  • Loading branch information
pykello committed Jul 24, 2016
1 parent 4c6f46c commit 0993421
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions include/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ void proc_shrink_memory(struct Process *proc, int page_count);
bool proc_load(struct Process *proc, char **proc_image, int page_count);
void proc_start(struct Process *proc);
int *get_current_context(void);
struct Process *proc_get(int pid);

/* scheduler.c */
void scheduler_init(void);
void schedule(void);
void dump_scheduler_status(void);

/* syscall_exec.c */
bool proc_load_program(struct Process *proc, int program_index);
Expand Down
8 changes: 8 additions & 0 deletions kernel/proc/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,11 @@ int *get_current_context(void)
{
return current_process->context;
}

struct Process *proc_get(int pid)
{
if (pid > 0 && pid <= PROCESS_COUNT_MAX)
return &process_table[pid - 1];
else
return NULL;
}
24 changes: 19 additions & 5 deletions kernel/proc/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void handle_timer(void)
void scheduler_init(void)
{
round_robin_index = 0;
timer_set_interval(100000);
timer_set_interval(200000);
register_interrupt_handler(TIMER_IRQ, handle_timer);
}

Expand All @@ -36,17 +36,31 @@ void schedule(void)
proc = &process_table[round_robin_index];

if (proc->state == READY) {
//kprintf("scheduling %d\n", round_robin_index);
current_process = proc;
proc_start(proc);
}
}

/* no process? panic */
mon_status(0, 0);
kprintf("round_robin_index = %d\n", round_robin_index);
for (i = 0; i < PROCESS_COUNT_MAX; i++)
kprintf("[%d] = %d\n", i, process_table[i].state);
dump_scheduler_status();
kprintf("PANIC");
while(1);
}

void dump_scheduler_status(void)
{
int i;
for (i = 0; i < PROCESS_COUNT_MAX; i++)
if (i == round_robin_index)
kprintf("v");
else
kprintf(" ");
kprintf("\n");
for (i = 0; i < PROCESS_COUNT_MAX; i++)
kprintf("%d", i);
kprintf("\n");
for (i = 0; i < PROCESS_COUNT_MAX; i++)
kprintf("%d", process_table[i].state);
kprintf("\n");
}
11 changes: 8 additions & 3 deletions kernel/proc/syscall_wait.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include <ksyscall.h>
#include <proc.h>
#include <system.h>
#include <klib.h>


int syscall_wait(int arg1)
{
current_process->wait_pid = arg1;
current_process->state = SLEEPING;
schedule();
struct Process *proc = proc_get(arg1);
if (proc && proc->state != UNUSED) {
current_process->wait_pid = arg1;
current_process->state = SLEEPING;
schedule();
}

return 0;
}

0 comments on commit 0993421

Please sign in to comment.