Merge branch 'single-exit-status' into 'master'
Use a single `exit_status` instead of two See merge request lab2425_autumn/pintos_22!50
This commit is contained in:
@@ -673,7 +673,7 @@ init_process_result (struct thread *t)
|
||||
{
|
||||
struct process_result *result = malloc (sizeof (struct process_result));
|
||||
result->tid = t->tid;
|
||||
result->exit_status = t->exit_status;
|
||||
result->exit_status = -1;
|
||||
lock_init (&result->lock);
|
||||
sema_init (&result->sema, 0);
|
||||
t->result = result;
|
||||
@@ -707,8 +707,6 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->recent_cpu = recent_cpu;
|
||||
t->priority = t->base_priority;
|
||||
|
||||
t->exit_status = -1;
|
||||
|
||||
old_level = intr_disable ();
|
||||
list_push_back (&all_list, &t->allelem);
|
||||
intr_set_level (old_level);
|
||||
|
||||
@@ -135,8 +135,6 @@ struct thread
|
||||
/* Shared between thread.c and synch.c. */
|
||||
struct list_elem elem; /* List element. */
|
||||
|
||||
int exit_status; /* Exit Status: 0 = successful exit. */
|
||||
|
||||
#ifdef USERPROG
|
||||
/* Owned by userprog/process.c. */
|
||||
uint32_t *pagedir; /* Page directory. */
|
||||
|
||||
@@ -56,7 +56,7 @@ struct process_start_data
|
||||
};
|
||||
|
||||
static thread_func start_process NO_RETURN;
|
||||
static void destruct_process_result (struct hash_elem *e, void *aux);
|
||||
static void destruct_process_result (struct hash_elem *e, void *aux UNUSED);
|
||||
static bool load (const char *cmdline, void (**eip) (void), void **esp);
|
||||
|
||||
/* Starts a new thread running a user program executed via
|
||||
@@ -355,8 +355,6 @@ process_exit (void)
|
||||
struct thread *cur = thread_current ();
|
||||
uint32_t *pd;
|
||||
|
||||
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
||||
|
||||
/* Clean up all open files */
|
||||
hash_destroy (&cur->open_files, fd_cleanup);
|
||||
|
||||
@@ -369,9 +367,12 @@ process_exit (void)
|
||||
lock_release (&filesys_lock);
|
||||
}
|
||||
|
||||
/* Update own process result. */
|
||||
if (cur->result != NULL)
|
||||
destruct_process_result (&cur->result->elem, cur);
|
||||
{
|
||||
printf ("%s: exit(%d)\n", cur->name, cur->result->exit_status);
|
||||
/* Update own process result. */
|
||||
destruct_process_result (&cur->result->elem, cur);
|
||||
}
|
||||
|
||||
/* Free child process results or signal parent's death. */
|
||||
hash_destroy (&cur->child_results, destruct_process_result);
|
||||
@@ -394,16 +395,12 @@ process_exit (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Destruct a process_result, with multi-thread awareness. Takes the
|
||||
process_result->elem and current thread.
|
||||
/* Destruct a process_result, with multi-thread awareness.
|
||||
If the other thread is running, simply signals death. Otherwise
|
||||
frees the result.
|
||||
Also set's process_result->exit_status if the process result is FOR
|
||||
the current thread. */
|
||||
frees the result. */
|
||||
static void
|
||||
destruct_process_result (struct hash_elem *e, void *cur_)
|
||||
destruct_process_result (struct hash_elem *e, void *aux UNUSED)
|
||||
{
|
||||
struct thread *cur = cur_;
|
||||
struct process_result *result = hash_entry (e, struct process_result, elem);
|
||||
lock_acquire (&result->lock);
|
||||
/* Other thread has died (and was not waited for). Free the result. */
|
||||
@@ -415,8 +412,6 @@ destruct_process_result (struct hash_elem *e, void *cur_)
|
||||
/* Other thread is still alive, signal via sema that parent has died. */
|
||||
else
|
||||
{
|
||||
if (cur->tid == result->tid)
|
||||
result->exit_status = cur->exit_status;
|
||||
sema_up (&result->sema);
|
||||
lock_release (&result->lock);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ syscall_exit (int status)
|
||||
{
|
||||
/* Sets exit_status of the thread to status. thread_exit () will call
|
||||
process_exit () if user programs are allowed. */
|
||||
thread_current ()->exit_status = status;
|
||||
thread_current ()->result->exit_status = status;
|
||||
thread_exit ();
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ syscall_read (int fd, void *buffer, unsigned size)
|
||||
{
|
||||
/* Reading from the console. */
|
||||
char *write_buffer = buffer;
|
||||
for (int i = 0; i < size; i++)
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
write_buffer[i] = input_getc ();
|
||||
|
||||
/* In case of console, read is always (eventually) successful. So return
|
||||
|
||||
Reference in New Issue
Block a user