Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jleong/change exit behavior #114

Merged
merged 12 commits into from
Feb 22, 2017
Next Next commit
Clean up code in preparation for refactor
  • Loading branch information
omegaphoenix committed Feb 20, 2017
commit 203ff2c070a1b358cc7eb52a17ca37ec45a364f2
1 change: 1 addition & 0 deletions src/threads/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ void thread_exit(void) {

if (kid != NULL && kid->status == THREAD_DYING
&& kid != initial_thread) {
list_remove(&kid->kid_elem);
palloc_free_page(kid);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/userprog/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ int process_wait(tid_t child_tid UNUSED) {
for (e = list_begin(&cur->kids); e != list_end(&cur->kids);
e = list_next(e)) {
kid = list_entry(e, struct thread, kid_elem);
lock_acquire(&kid->filesys_lock);
if (kid->tid == child_tid && !kid->waited_on) {
/* Next time we look for this kid, we return -1. */
kid->waited_on = true;
lock_release(&kid->filesys_lock);
break;
}
lock_release(&kid->filesys_lock);
}

/* Check if no kid with child_tid. */
Expand All @@ -168,9 +171,6 @@ int process_wait(tid_t child_tid UNUSED) {
/* Wait for child thread to die. */
sema_down(&kid->wait_sema);

/* Thread exit should have already been called. */
ASSERT(kid->status == THREAD_DYING);

/* If child thread is done, just get exit status. */
int child_exit_status = kid->exit_status;
kid->parent = NULL;
Expand All @@ -187,6 +187,11 @@ void process_exit(void) {
struct thread *cur = thread_current();
uint32_t *pd;

/* Free executable */
if (cur->executable != NULL) {
file_allow_write(cur->executable);
}

/* Destroy the current process's page directory and switch back
to the kernel-only page directory. */
pd = cur->pagedir;
Expand Down
20 changes: 2 additions & 18 deletions src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,14 @@ void sys_halt(void) {
void sys_exit(int status) {
struct thread *cur = thread_current();
printf("%s: exit(%d)\n", cur->name, status);

cur->exit_status = status;

if (lock_held_by_current_thread(&filesys_lock)) {
release_file_lock();
}

/* Free executable */
if (cur->executable != NULL) {
file_allow_write(cur->executable);
}

/* Free all file buffers. */
struct list_elem *e;
for (e = list_begin(&cur->open_files);
e != list_end(&cur->open_files);
/* increment in loop */) {
while (!list_empty(&cur->open_files)) {
e = list_begin(&cur->open_files);
struct sys_file *open_file =
list_entry(e, struct sys_file, file_elem);

/* Increment before removing. */
e = list_next(e);

/* File system call */
sys_close(open_file->fd);
}
thread_exit();
Expand Down